Skip to content

add auth escape hatch docs for android #7686

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 7, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 70 additions & 2 deletions src/pages/[platform]/build-a-backend/auth/use-aws-sdk/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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'
],
};

Expand All @@ -21,9 +22,10 @@ export function getStaticProps(context) {
};
}

<InlineFilter filters={['swift']}>
For advanced use cases where Amplify does not provide the functionality, you can retrieve an escape hatch to access the underlying Amazon Cognito client.

<InlineFilter filters={['swift']}>

<Callout warning>

**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.
Expand Down Expand Up @@ -58,3 +60,69 @@ func getEscapeHatch() {
}
```
</InlineFilter>

<InlineFilter filters={["android"]}>
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"
```
<BlockSwitcher>
<Block name="Kotlin">

```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)
}
```

</Block>
<Block name="Java">

<Callout>

[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).

</Callout>

```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<ResendConfirmationCodeResponse>() {
@NonNull
@Override
public CoroutineContext getContext() {
return GlobalScope.INSTANCE.getCoroutineContext();
}

@Override
public void resumeWith(@NonNull Object resultOrException) {
Log.i(TAG, "Result: " + resultOrException);
}
});
```

</Block>
</BlockSwitcher>
</InlineFilter>
Loading