From f8f696983cd18ee3f0467b3db9dc4f496f5ab13d Mon Sep 17 00:00:00 2001 From: shah Date: Thu, 4 Jul 2024 15:21:00 +0530 Subject: [PATCH 1/2] feat: code optimize --- .../amazon/location/auth/AuthHelper.kt | 24 +++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/library/src/main/java/software/amazon/location/auth/AuthHelper.kt b/library/src/main/java/software/amazon/location/auth/AuthHelper.kt index b856ff4..0c5c299 100644 --- a/library/src/main/java/software/amazon/location/auth/AuthHelper.kt +++ b/library/src/main/java/software/amazon/location/auth/AuthHelper.kt @@ -75,9 +75,29 @@ class AuthHelper(private val context: Context) { /** * Authenticates using a region and a specified CredentialsProvider. + * + * For example, to get credentials from AWS Kotlin SDK: + * 1. Use `CognitoIdentityClient` to call `.getId` to get the identity ID: + * ``` kotlin + * val identityId = cognitoIdentityClient.getId(GetIdRequest { this.identityPoolId = identityPoolId }).identityId + * ``` + * + * 2. Use `CognitoIdentityClient` to call `.getCredentialsForIdentity` with the identity ID to get the credentials: + * ``` kotlin + * val credentials = cognitoIdentityClient.getCredentialsForIdentity(GetCredentialsForIdentityRequest { this.identityId = identityId }).credentials + * ``` + * + * + * To create a `StaticCredentialsProvider` as a `CredentialsProvider` from the obtained credentials: + * 1. Use the credentials obtained in the previous steps: + * ``` kotlin + * val staticCredentialsProvider = StaticCredentialsProvider(credentials) + * ``` + * + * * @param region The AWS region as a string. - * @param credentialsProvider The CredentialsProvider from AWS kotlin SDK. - * @return A LocationCredentialsProvider object. + * @param credentialsProvider The `CredentialsProvider` from AWS Kotlin SDK (`aws.smithy.kotlin.runtime.auth.awscredentials`). + * @return A `LocationCredentialsProvider` object. */ suspend fun authenticateWithCredentialsProvider( region: String, From c00a3dbfb04616673af56ee5056cd18baecd8a69 Mon Sep 17 00:00:00 2001 From: shah Date: Thu, 4 Jul 2024 15:36:17 +0530 Subject: [PATCH 2/2] feat: code optimization --- .../java/software/amazon/location/auth/AuthHelper.kt | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/library/src/main/java/software/amazon/location/auth/AuthHelper.kt b/library/src/main/java/software/amazon/location/auth/AuthHelper.kt index 0c5c299..3aeb83f 100644 --- a/library/src/main/java/software/amazon/location/auth/AuthHelper.kt +++ b/library/src/main/java/software/amazon/location/auth/AuthHelper.kt @@ -91,10 +91,16 @@ class AuthHelper(private val context: Context) { * To create a `StaticCredentialsProvider` as a `CredentialsProvider` from the obtained credentials: * 1. Use the credentials obtained in the previous steps: * ``` kotlin - * val staticCredentialsProvider = StaticCredentialsProvider(credentials) + * val staticCredentialsProvider = StaticCredentialsProvider( + * aws.smithy.kotlin.runtime.auth.awscredentials.Credentials.invoke( + * accessKeyId = credentials.accessKeyId, + * secretAccessKey = credentials.secretKey, + * sessionToken = credentials.sessionToken, + * expiration = credentials.expiration + * ) + * ) * ``` * - * * @param region The AWS region as a string. * @param credentialsProvider The `CredentialsProvider` from AWS Kotlin SDK (`aws.smithy.kotlin.runtime.auth.awscredentials`). * @return A `LocationCredentialsProvider` object.