Skip to content
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

Update Auth SDK to support Standalone Maps, Places, Routes SDKs and align APIs with other platforms #14

Merged
merged 12 commits into from
Oct 31, 2024
Merged
69 changes: 51 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,34 @@ 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("software.amazon.location:auth:1.0.0")
implementation("org.maplibre.gl:android-sdk:11.5.2")
implementation("com.squareup.okhttp3:okhttp:4.12.0")
```

For the new standalone Maps / Places / Routes SDKs, add the following lines:
```
implementation("aws.sdk.kotlin:geomaps:1.3.65")
implementation("aws.sdk.kotlin:geoplaces:1.3.65")
implementation("aws.sdk.kotlin:georoutes:1.3.65")
```

For the consolidated Location SDK that includes Geofencing and Tracking, add the following line:
```
implementation("aws.sdk.kotlin:location:1.3.65")
```

## Usage

Import the following classes in your code:

```
// For the standalone Maps / Places / Routes SDKs
import aws.sdk.kotlin.services.geomaps.GeoMapsClient
import aws.sdk.kotlin.services.geoplaces.GeoPlacesClient
import aws.sdk.kotlin.services.georoutes.GeoRoutesClient

// For the consolidated Location SDK
import aws.sdk.kotlin.services.location.LocationClient

import software.amazon.location.auth.AuthHelper
Expand All @@ -36,27 +53,44 @@ 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()
val authHelper = AuthHelper.withCognitoIdentityPool("MY-COGNITO-IDENTITY-POOL-ID")

// Get instances of the standalone clients:
var geoMapsClient = GeoMapsClient(authHelper?.getGeoMapsClientConfig())
var geoPlacesClient = GeoPlacesClient(authHelper?.getGeoPlacesClientConfig())
var geoRoutesClient = GeoRoutesClient(authHelper?.getGeoRoutesClientConfig())

// Get an instance of the Location client:
var locationClient = LocationClient(authHelper?.getLocationClientConfig())
}

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()
}
var authHelper = AuthHelper.withCredentialsProvider(MY-CUSTOM-CREDENTIAL-PROVIDER, "MY-AWS-REGION")

// Get instances of the standalone clients:
var geoMapsClient = GeoMapsClient(authHelper?.getGeoMapsClientConfig())
var geoPlacesClient = GeoPlacesClient(authHelper?.getGeoPlacesClientConfig())
var geoRoutesClient = GeoRoutesClient(authHelper?.getGeoRoutesClientConfig())

// Get an instance of the Location client:
var locationClient = LocationClient(authHelper?.getLocationClientConfig())

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()
var authHelper = AuthHelper.withApiKey("MY-API-KEY", "MY-AWS-REGION")

// Get instances of the standalone clients:
var geoMapsClient = GeoMapsClient(authHelper?.getGeoMapsClientConfig())
var geoPlacesClient = GeoPlacesClient(authHelper?.getGeoPlacesClientConfig())
var geoRoutesClient = GeoRoutesClient(authHelper?.getGeoRoutesClientConfig())

// Get an instance of the Location client:
var locationClient = LocationClient(authHelper?.getLocationClientConfig())
}
```
You can use the LocationCredentialsProvider to load the maplibre map. Here is an example of that:
Expand All @@ -76,16 +110,15 @@ HttpRequestUtil.setOkHttpClient(
)
```

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:
You can use the created clients 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)
val suggestRequest = SuggestRequest {
biasPosition = listOf(-97.718833, 30.405423)
maxResults = MAX_RESULT
language = "PREFERRED-LANGUAGE"
}
val nearbyPlaces = locationClient.searchPlaceIndexForPosition(request)
val nearbyPlaces = geoPlacesClient.suggest(suggestRequest)
```

## Security
Expand Down
4 changes: 2 additions & 2 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
plugins {
id("org.jetbrains.kotlin.android") version "1.9.0" apply false
id("com.android.library") version "8.2.2" apply false
id("org.jetbrains.kotlin.android") version "1.9.21" apply false
id("com.android.library") version "8.3.2" apply false
}
26 changes: 26 additions & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,40 @@
# https://docs.gradle.org/current/userguide/platforms.html#sub::toml-dependencies-format

[versions]
androidx-junit = "1.2.1"
appcompat = "1.7.0"
commons-math3 = "3.6.1"
core-ktx = "1.15.0"
espresso-core = "3.6.1"
guava = "32.1.3-jre"
junit = "4.13.2"
junit-jupiter-engine = "5.10.0"
kotlin-test = "2.0.21"
location = "1.3.65"
material = "1.12.0"
mockk = "1.13.13"
okhttp = "4.12.0"
security-crypto = "1.1.0-alpha06"

[libraries]
appcompat = { module = "androidx.appcompat:appcompat", version.ref = "appcompat" }
cognitoidentity = { module = "aws.sdk.kotlin:cognitoidentity", version.ref = "location" }
commons-math3 = { module = "org.apache.commons:commons-math3", version.ref = "commons-math3" }
core-ktx = { module = "androidx.core:core-ktx", version.ref = "core-ktx" }
espresso-core = { module = "androidx.test.espresso:espresso-core", version.ref = "espresso-core" }
ext-junit = { module = "androidx.test.ext:junit", version.ref = "androidx-junit" }
geomaps = { module = "aws.sdk.kotlin:geomaps", version.ref = "location" }
geoplaces = { module = "aws.sdk.kotlin:geoplaces", version.ref = "location" }
georoutes = { module = "aws.sdk.kotlin:georoutes", version.ref = "location" }
guava = { module = "com.google.guava:guava", version.ref = "guava" }
junit = { module = "junit:junit", version.ref = "junit" }
junit-jupiter-engine = { module = "org.junit.jupiter:junit-jupiter-engine", version.ref = "junit-jupiter-engine" }
kotlin-test = { module = "org.jetbrains.kotlin:kotlin-test", version.ref = "kotlin-test" }
location = { module = "aws.sdk.kotlin:location", version.ref = "location" }
material = { module = "com.google.android.material:material", version.ref = "material" }
mockk = { module = "io.mockk:mockk", version.ref = "mockk" }
okhttp = { module = "com.squareup.okhttp3:okhttp", version.ref = "okhttp" }
security-crypto = { module = "androidx.security:security-crypto", version.ref = "security-crypto" }

[plugins]
jvm = { id = "org.jetbrains.kotlin.jvm", version = "1.9.20" }
29 changes: 16 additions & 13 deletions library/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ mavenPublishing {
publishToMavenCentral(SonatypeHost.DEFAULT, automaticRelease = true)
signAllPublications()

coordinates("software.amazon.location", "auth", "0.2.5")
coordinates("software.amazon.location", "auth", "1.0.0")

pom {
name.set("Amazon Location Service Mobile Authentication SDK for Android")
Expand Down Expand Up @@ -83,18 +83,21 @@ android {
}

dependencies {
implementation("androidx.core:core-ktx:1.13.1")
implementation("androidx.appcompat:appcompat:1.7.0")
implementation("com.google.android.material:material:1.12.0")
implementation("androidx.security:security-crypto:1.1.0-alpha06")
implementation("aws.sdk.kotlin:cognitoidentity:1.3.29")
implementation("aws.sdk.kotlin:location:1.3.29")
implementation("com.squareup.okhttp3:okhttp:4.12.0")
implementation(libs.core.ktx)
implementation(libs.appcompat)
implementation(libs.material)
implementation(libs.security.crypto)
implementation(libs.cognitoidentity)
implementation(libs.location)
implementation(libs.geomaps)
implementation(libs.geoplaces)
implementation(libs.georoutes)
implementation(libs.okhttp)

testImplementation("junit:junit:4.13.2")
testImplementation("org.jetbrains.kotlin:kotlin-test:1.9.20")
testImplementation("io.mockk:mockk:1.13.10")
testImplementation(libs.junit)
testImplementation(libs.kotlin.test)
testImplementation(libs.mockk)

androidTestImplementation("androidx.test.ext:junit:1.2.1")
androidTestImplementation("androidx.test.espresso:espresso-core:3.6.1")
androidTestImplementation(libs.ext.junit)
androidTestImplementation(libs.espresso.core)
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

package software.amazon.location.auth

import aws.smithy.kotlin.runtime.client.ProtocolRequestInterceptorContext
Expand All @@ -14,11 +17,11 @@ class ApiKeyInterceptor(
override suspend fun modifyBeforeSigning(context: ProtocolRequestInterceptorContext<Any, HttpRequest>): HttpRequest {
val req = context.protocolRequest.toBuilder()

if (!context.protocolRequest.url.toString().contains("$QUERY_PARAM_KEY=")) {
return if (!context.protocolRequest.url.toString().contains("$QUERY_PARAM_KEY=")) {
req.url(Url.parse(context.protocolRequest.url.toString()+"?$QUERY_PARAM_KEY=$apiKey"))
return req.build()
req.build()
} else {
return super.modifyBeforeSigning(context)
super.modifyBeforeSigning(context)
}
}
}
Loading
Loading