Skip to content

Commit

Permalink
Merge pull request #19 from makeen-project/pr_comment
Browse files Browse the repository at this point in the history
Code optimization
  • Loading branch information
olegfilimonov authored Jul 4, 2024
2 parents 0941d1c + c00a3db commit 8036766
Showing 1 changed file with 28 additions and 2 deletions.
30 changes: 28 additions & 2 deletions library/src/main/java/software/amazon/location/auth/AuthHelper.kt
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,35 @@ 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(
* 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.
* @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,
Expand Down

0 comments on commit 8036766

Please sign in to comment.