Skip to content

ejboucher/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 or API keys as the authentication method.

Installation

This authentication SDK works with the overall AWS 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.0.2")
implementation("aws.sdk.kotlin:location:1.2.21")
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 an authentication helper instance using an Amazon Location API Key
private fun exampleAPIKeyLogin() {
    var authHelper = AuthHelper(applicationContext)
    var locationCredentialsProvider : LocationCredentialsProvider = authHelper.authenticateWithApiKey("My-Amazon-Location-API-Key")
    var locationClient = locationCredentialsProvider?.getLocationClient()
}
// Create an authentication helper using credentials from Cognito
private fun exampleCognitoLogin() {
    var authHelper = AuthHelper(applicationContext)
    var locationCredentialsProvider : LocationCredentialsProvider = authHelper.authenticateWithCognitoIdentityPool("My-Cognito-Identity-Pool-Id")
    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(
                "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

Packages

No packages published

Languages

  • Kotlin 100.0%