Skip to content

makeen-project/amazon-location-mobile-auth-sdk-android

 
 

Repository files navigation

Amazon Location Service Mobile Authentication SDK for Android

These utilities help you authenticate when making Amazon Location Service API calls from your Android applications. This specifically helps when using Amazon Cognito as the authentication method.

Installation

This authentication SDK works with the overall AWS Kotlin SDK. Both SDKs are published to Maven Central. Check the latest version of auth SDK on Maven Central.

Add the following lines to the dependencies section of your build.gradle file in Android Studio:

implementation("software.amazon.location:auth:0.2.5")
implementation("aws.sdk.kotlin:location:1.3.29")
implementation("org.maplibre.gl:android-sdk:11.0.0-pre5")
implementation("com.squareup.okhttp3:okhttp:4.12.0")

Usage

Import the following classes in your code:

import aws.sdk.kotlin.services.location.LocationClient

import software.amazon.location.auth.AuthHelper
import software.amazon.location.auth.LocationCredentialsProvider
import software.amazon.location.auth.AwsSignerInterceptor
import org.maplibre.android.module.http.HttpRequestUtil
import okhttp3.OkHttpClient

You can create an AuthHelper and use it with the AWS Kotlin SDK:

// Create a credential provider using Identity Pool Id with AuthHelper
private suspend fun exampleCognitoLogin() {
    var authHelper = AuthHelper(applicationContext)
    var locationCredentialsProvider : LocationCredentialsProvider = authHelper.authenticateWithCognitoIdentityPool("MY-COGNITO-IDENTITY-POOL-ID")
    var locationClient = locationCredentialsProvider?.getLocationClient()
}

OR

// Create a credential provider using custom credential provider with AuthHelper
private suspend fun exampleCustomCredentialLogin() {
    var authHelper = AuthHelper(applicationContext)
    var locationCredentialsProvider : LocationCredentialsProvider = authHelper.authenticateWithCredentialsProvider("MY-AWS-REGION", MY-CUSTOM-CREDENTIAL-PROVIDER)
    var locationClient = locationCredentialsProvider?.getLocationClient()
}

OR

// Create a credential provider using Api key with AuthHelper
private suspend fun exampleApiKeyLogin() {
    var authHelper = AuthHelper(applicationContext)
    var locationCredentialsProvider : LocationCredentialsProvider = authHelper.authenticateWithApiKey("MY-API-KEY", "MY-AWS-REGION")
    var locationClient = locationCredentialsProvider?.getLocationClient()
}

You can use the LocationCredentialsProvider to load the maplibre map. Here is an example of that:

HttpRequestUtil.setOkHttpClient(
    OkHttpClient.Builder()
        .addInterceptor(
            AwsSignerInterceptor(
                applicationContext,
                "geo",
                "MY-AWS-REGION",
                locationCredentialsProvider
            )
        )
        .build()
)

You can use the LocationClient to make calls to Amazon Location Service. Here is an example that searches for places near a specified latitude and longitude:

val searchPlaceIndexForPositionRequest = SearchPlaceIndexForPositionRequest {
       indexName = "My-Place-Index-Name"
       position = listOf(30.405423, -97.718833)
       maxResults = MAX_RESULT
       language = "PREFERRED-LANGUAGE"
   }
val nearbyPlaces = locationClient.searchPlaceIndexForPosition(request)

Security

See CONTRIBUTING for more information.

Getting Help

The best way to interact with our team is through GitHub. You can open an issue and choose from one of our templates for bug reports, feature requests or guidance. If you have a support plan with AWS Support, you can also create a new support case.

Contributing

We welcome community contributions and pull requests. See CONTRIBUTING.md for information on how to set up a development environment and submit code.

License

The Amazon Location Service Mobile Authentication SDK for Android is distributed under the Apache License, Version 2.0, see LICENSE.txt and NOTICE.txt for more information.

About

No description, website, or topics provided.

Resources

License

Code of conduct

Security policy

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Kotlin 100.0%