@@ -10,6 +10,30 @@ public protocol CredentialsProviding {
10
10
func getCredentials( ) async throws -> Credentials
11
11
}
12
12
13
+ /// A pair defining an identity provider and a valid login token sourced from it.
14
+ public struct CognitoLoginPair : CStruct {
15
+ public var IdentityProviderName : String
16
+ public var IdentityProviderToken : String
17
+
18
+ public init ( identityProviderName: String ,
19
+ identityProviderToken: String ) {
20
+ self . IdentityProviderName = identityProviderName
21
+ self . IdentityProviderToken = identityProviderToken
22
+ }
23
+
24
+ typealias RawType = aws_cognito_identity_provider_token_pair
25
+ func withCStruct< Result> ( _ body: ( aws_cognito_identity_provider_token_pair ) -> Result ) -> Result {
26
+ var token_pair = aws_cognito_identity_provider_token_pair ( )
27
+
28
+ return withByteCursorFromStrings ( IdentityProviderName,
29
+ IdentityProviderToken) { identityProviderNameCursor, IdentityProviderTokenCursor in
30
+ token_pair. identity_provider_name = identityProviderNameCursor
31
+ token_pair. identity_provider_token = IdentityProviderTokenCursor
32
+ return body ( token_pair)
33
+ }
34
+ }
35
+ }
36
+
13
37
public class CredentialsProvider : CredentialsProviding {
14
38
15
39
let rawValue : UnsafeMutablePointer < aws_credentials_provider >
@@ -294,6 +318,7 @@ extension CredentialsProvider.Source {
294
318
/// - Throws: CommonRuntimeError.crtError
295
319
public static func `defaultChain`( bootstrap: ClientBootstrap ,
296
320
fileBasedConfiguration: FileBasedConfiguration ,
321
+ tlsContext: TLSContext ? = nil ,
297
322
shutdownCallback: ShutdownCallback ? = nil ) -> Self {
298
323
Self {
299
324
let shutdownCallbackCore = ShutdownCallbackCore ( shutdownCallback)
@@ -302,6 +327,7 @@ extension CredentialsProvider.Source {
302
327
chainDefaultOptions. bootstrap = bootstrap. rawValue
303
328
chainDefaultOptions. profile_collection_cached = fileBasedConfiguration. rawValue
304
329
chainDefaultOptions. shutdown_options = shutdownCallbackCore. getRetainedCredentialProviderShutdownOptions ( )
330
+ chainDefaultOptions. tls_ctx = tlsContext? . rawValue
305
331
306
332
guard let provider = aws_credentials_provider_new_chain_default ( allocator. rawValue,
307
333
& chainDefaultOptions)
@@ -567,6 +593,64 @@ extension CredentialsProvider.Source {
567
593
return provider
568
594
}
569
595
}
596
+
597
+ /// Credential Provider that sources credentials from Cognito Identity service
598
+ /// - Parameters:
599
+ /// - bootstrap: Connection bootstrap to use for any network connections made while sourcing credentials
600
+ /// - tlsContext: TLS configuration for secure socket connections.
601
+ /// - endpoint: Cognito service regional endpoint to source credentials from.
602
+ /// - identity: Cognito identity to fetch credentials relative to.
603
+ /// - logins: (Optional) set of identity provider token pairs to allow for authenticated identity access.
604
+ /// - customRoleArn: (Optional) ARN of the role to be assumed when multiple roles were received in the token from the identity provider.
605
+ /// - proxyOptions: (Optional) Http proxy configuration for the http request that fetches credentials
606
+ /// - shutdownCallback: (Optional) shutdown callback
607
+ /// - Returns: `CredentialsProvider`
608
+ /// - Throws: CommonRuntimeError.crtError
609
+ public static func `cognito`( bootstrap: ClientBootstrap ,
610
+ tlsContext: TLSContext ,
611
+ endpoint: String ,
612
+ identity: String ,
613
+ logins: [ CognitoLoginPair ] = [ ] ,
614
+ customRoleArn: String ? = nil ,
615
+ proxyOptions: HTTPProxyOptions ? = nil ,
616
+ shutdownCallback: ShutdownCallback ? = nil ) -> Self {
617
+ Self {
618
+ var cognitoOptions = aws_credentials_provider_cognito_options ( )
619
+ cognitoOptions. bootstrap = bootstrap. rawValue
620
+ cognitoOptions. tls_ctx = tlsContext. rawValue
621
+ let shutdownCallbackCore = ShutdownCallbackCore ( shutdownCallback)
622
+ cognitoOptions. shutdown_options = shutdownCallbackCore. getRetainedCredentialProviderShutdownOptions ( )
623
+
624
+ guard let provider: UnsafeMutablePointer < aws_credentials_provider > = ( withByteCursorFromStrings (
625
+ endpoint,
626
+ identity) { endpointCursor, identityCursor in
627
+
628
+ cognitoOptions. endpoint = endpointCursor
629
+ cognitoOptions. identity = identityCursor
630
+
631
+ return withOptionalCStructPointer ( to: proxyOptions) { proxyOptionsPointer in
632
+ cognitoOptions. http_proxy_options = proxyOptionsPointer
633
+
634
+ return logins. withAWSArrayList { loginArrayPointer in
635
+ cognitoOptions. logins = UnsafeMutablePointer < aws_cognito_identity_provider_token_pair > ( loginArrayPointer)
636
+ cognitoOptions. login_count = logins. count
637
+
638
+ return withOptionalByteCursorPointerFromString ( customRoleArn, { customRoleArnCursor in
639
+ if let customRoleArnCursor {
640
+ cognitoOptions. custom_role_arn = UnsafeMutablePointer < aws_byte_cursor > ( mutating: customRoleArnCursor)
641
+ }
642
+ return aws_credentials_provider_new_cognito_caching ( allocator. rawValue, & cognitoOptions)
643
+ } )
644
+ }
645
+ }
646
+ } )
647
+ else {
648
+ shutdownCallbackCore. release ( )
649
+ throw CommonRunTimeError . crtError ( CRTError . makeFromLastError ( ) )
650
+ }
651
+ return provider
652
+ }
653
+ }
570
654
}
571
655
572
656
private func onGetCredentials( credentials: OpaquePointer ? ,
0 commit comments