From d0ee003c4ba16fe8f0fd96c3ea17aa6e44925fc6 Mon Sep 17 00:00:00 2001 From: Harshita Daddala Date: Fri, 31 May 2024 09:58:47 -0400 Subject: [PATCH 1/2] add auth escape hatch docs for android --- .../auth/use-aws-sdk/index.mdx | 72 ++++++++++++++++++- 1 file changed, 70 insertions(+), 2 deletions(-) diff --git a/src/pages/[platform]/build-a-backend/auth/use-aws-sdk/index.mdx b/src/pages/[platform]/build-a-backend/auth/use-aws-sdk/index.mdx index 777c899d688..c851a65ef1d 100644 --- a/src/pages/[platform]/build-a-backend/auth/use-aws-sdk/index.mdx +++ b/src/pages/[platform]/build-a-backend/auth/use-aws-sdk/index.mdx @@ -4,7 +4,8 @@ export const meta = { title: 'Use AWS SDK', description: 'For advanced use cases where Amplify does not provide the functionality, you can retrieve the escape hatch to access the AWSCognito instance.', platforms: [ - 'swift' + 'swift', + 'android' ], }; @@ -21,9 +22,10 @@ export function getStaticProps(context) { }; } - For advanced use cases where Amplify does not provide the functionality, you can retrieve an escape hatch to access the underlying Amazon Cognito client. + + **Note:** While the Amplify Library for Swift is production ready, please note that the underlying AWS SDK for Swift is currently in Developer Preview, and is not yet intended for production workloads. [Here is additional reading material](https://github.com/awslabs/aws-sdk-swift/blob/main/Sources/Core/AWSSDKForSwift/Documentation.docc/stability.md) on the stability of the SDK. @@ -58,3 +60,69 @@ func getEscapeHatch() { } ``` + + +You can access the underlying `CognitoIdentityProviderClient` and `CognitoIdentityClient` as shown below + +```kotlin +implementation "aws.sdk.kotlin:cognitoidentityprovider:1.0.44" +implementation "aws.sdk.kotlin:cognitoidentity:1.0.44" +``` + + + +```kotlin +suspend fun resendCodeUsingEscapeHatch() { + // Get the instance of AWSCognitoAuthPlugin + val cognitoAuthPlugin = Amplify.Auth.getPlugin("awsCognitoAuthPlugin") + val cognitoAuthService = cognitoAuthPlugin.escapeHatch as AWSCognitoAuthService + + // Get the instance of CognitoIdentityProviderClient + val cognitoIdentityProviderClient = cognitoAuthService.cognitoIdentityProviderClient + val request = ResendConfirmationCodeRequest { + clientId = "xxxxxxxxxxxxxxxx" + username = "user1" + } + val response = cognitoIdentityProviderClient?.resendConfirmationCode(request) +} +``` + + + + + + +Learn more about consuming Kotlin clients from Java using either a blocking interface or an equivalent async interface based on futures [here](https://github.com/awslabs/smithy-kotlin/blob/main/docs/design/kotlin-smithy-sdk.md#java-interop). + + + +```java +// Get the instance of AWSCognitoAuthPlugin +AWSCognitoAuthPlugin cognitoAuthPlugin = (AWSCognitoAuthPlugin) Amplify.Auth.getPlugin("awsCognitoAuthPlugin"); + +// Get the instance of CognitoIdentityProviderClient +CognitoIdentityProviderClient client = cognitoAuthPlugin.getEscapeHatch().getCognitoIdentityProviderClient(); +ResendConfirmationCodeRequest request = ResendConfirmationCodeRequest.Companion.invoke(dslBuilder -> { + dslBuilder.setClientId("xxxxxxxxxxxxxxxx"); + dslBuilder.setUsername("user1"); + return null; +}); + +assert client != null; +client.resendConfirmationCode(request, new Continuation() { + @NonNull + @Override + public CoroutineContext getContext() { + return GlobalScope.INSTANCE.getCoroutineContext(); + } + + @Override + public void resumeWith(@NonNull Object resultOrException) { + Log.i(TAG, "Result: " + resultOrException); + } +}); +``` + + + + From 4dab836950c44627b030ac8b3db662b1b148b596 Mon Sep 17 00:00:00 2001 From: Harshita Daddala Date: Thu, 6 Jun 2024 18:22:02 -0400 Subject: [PATCH 2/2] Update src/pages/[platform]/build-a-backend/auth/use-aws-sdk/index.mdx Co-authored-by: josef --- src/pages/[platform]/build-a-backend/auth/use-aws-sdk/index.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pages/[platform]/build-a-backend/auth/use-aws-sdk/index.mdx b/src/pages/[platform]/build-a-backend/auth/use-aws-sdk/index.mdx index c851a65ef1d..117fc45372f 100644 --- a/src/pages/[platform]/build-a-backend/auth/use-aws-sdk/index.mdx +++ b/src/pages/[platform]/build-a-backend/auth/use-aws-sdk/index.mdx @@ -92,7 +92,7 @@ suspend fun resendCodeUsingEscapeHatch() { -Learn more about consuming Kotlin clients from Java using either a blocking interface or an equivalent async interface based on futures [here](https://github.com/awslabs/smithy-kotlin/blob/main/docs/design/kotlin-smithy-sdk.md#java-interop). +[Learn more about consuming Kotlin clients from Java using either a blocking interface or an equivalent async interface based on futures](https://github.com/awslabs/smithy-kotlin/blob/main/docs/design/kotlin-smithy-sdk.md#java-interop).