Skip to content

Files

Latest commit

 

History

History
202 lines (143 loc) · 8.19 KB

File metadata and controls

202 lines (143 loc) · 8.19 KB

Amazon Location Service Mobile Authentication SDK for iOS

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

Installation

  1. Go to File -> Add Package Dependencies in your XCode project.
  2. Type the package URL (https://github.com/aws-geospatial/amazon-location-mobile-auth-sdk-ios/) into the search bar and press the enter key.
  3. Select the "amazon-location-mobile-auth-sdk-ios" package and click on "Add Package".
  4. Select the "AmazonLocationiOSAuthSDK" package product and click on "Add Package".

Usage

After installing the library, use the AuthHelper class to retrieve your desired client configuration for either API keys or Amazon Cognito.

API keys

Here is an example using the standalone Places SDK with the API key authentication method:

import AmazonLocationiOSAuthSDK
import AWSGeoPlaces

func geoPlacesExample() {
    let apiKey = "<API key>"
    let region = "<Region>"

    // Create an authentication helper using your API key and region
    let authHelper = try await AuthHelper.withApiKey(apiKey: apiKey, region: region)

    // Configure the GeoPlacesClient to use API keys when making requests
    let client: GeoPlacesClient = GeoPlacesClient(config: authHelper.getGeoPlacesClientConfig())

    // Construct the input for the request
    let input = AWSGeoPlaces.SearchTextInput(
        biasPosition: [-97.7457518, 30.268193],
        queryText: "tacos"
    )

    // Use the client to send the request
    let output = try await client.searchText(input: input)
}

Here is an example using the standalone Routes SDK with the API key authentication method:

import AmazonLocationiOSAuthSDK
import AWSGeoRoutes

func geoRoutesExample() {
    let apiKey = "<API key>"
    let region = "<Region>"

    // Create an authentication helper using your API key and region
    let authHelper = try await AuthHelper.withApiKey(apiKey: apiKey, region: region)

    // Configure the GeoRoutesClient to use API keys when making requests
    let client: GeoRoutesClient = GeoRoutesClient(config: authHelper.getGeoRoutesClientConfig())

    // Construct the input for the request
    let input = AWSGeoRoutes.CalculateRoutesInput(
        destination: [-123.1651031, 49.2577281],
        origin: [-97.7457518, 30.268193]
    )

    // Use the client to send the request
    let output = try await client.calculateRoutes(input: input)
}

Here is an example using the Location SDK with the API key authentication method:

import AmazonLocationiOSAuthSDK
import AWSLocation

func locationExample() {
    let apiKey = "<API key>"
    let region = "<Region>"

    // Create an authentication helper using your API key and region
    let authHelper = try await AuthHelper.withApiKey(apiKey: apiKey, region: region)

    // Configure the LocationClient to use API keys when making requests
    let client: LocationClient = LocationClient(config: authHelper.getLocationClientConfig())

    // Construct the input for the request
    let input = AWSLocation.ListGeofencesInput(
        collectionName: "<Collection name>"
    )

    // Use the client to send the request
    let output = try await client.listGeofences(input: input)
}

Amazon Cognito

Here is an example using the standalone Places SDK with the Amazon Cognito authentication method:

import AmazonLocationiOSAuthSDK
import AWSGeoPlaces

func geoPlacesExample() {
    let identityPoolId = "<Identity Pool ID>"

    // Create an authentication helper using credentials from Cognito
    let authHelper = try await AuthHelper.withIdentityPoolId(identityPoolId: identityPoolId)

    // Configure the GeoPlacesClient to use credentials obtained via Amazon Cognito
    let client: GeoPlacesClient = GeoPlacesClient(config: authHelper.getGeoPlacesClientConfig())

    // Construct the input for the request
    let input = AWSGeoPlaces.SearchTextInput(
        biasPosition: [-97.7457518, 30.268193],
        queryText: "tacos"
    )

    // Use the client to send the request
    let output = try await client.searchText(input: input)
}

Here is an example using the standalone Routes SDK with the Amazon Cognito authentication method:

import AmazonLocationiOSAuthSDK
import AWSGeoRoutes

func geoRoutesExample() {
    let identityPoolId = "<Identity Pool ID>"

    // Create an authentication helper using credentials from Cognito
    let authHelper = try await AuthHelper.withIdentityPoolId(identityPoolId: identityPoolId)

    // Configure the GeoRoutesClient to use credentials obtained via Amazon Cognito
    let client: GeoRoutesClient = GeoRoutesClient(config: authHelper.getGeoRoutesClientConfig())

    // Construct the input for the request
    let input = AWSGeoRoutes.CalculateRoutesInput(
        destination: [-123.1651031, 49.2577281],
        origin: [-97.7457518, 30.268193]
    )

    // Use the client to send the request
    let output = try await client.calculateRoutes(input: input)
}

Here is an example using the Location SDK with the Amazon Cognito authentication method:

import AmazonLocationiOSAuthSDK
import AWSLocation

func locationExample() {
    let identityPoolId = "<Identity Pool ID>"

    // Create an authentication helper using credentials from Cognito
    let authHelper = try await AuthHelper.withIdentityPoolId(identityPoolId: identityPoolId)

    // Configure the LocationClient to use credentials obtained via Amazon Cognito
    let client: LocationClient = LocationClient(config: authHelper.getLocationClientConfig())

    // Construct the input for the request
    let input = AWSLocation.ListGeofencesInput(
        collectionName: "<Collection name>"
    )

    // Use the client to send the request
    let output = try await client.listGeofences(input: input)
}

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.

Please make sure to check out the following resources before opening an issue:

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 iOS is distributed under the Apache License, Version 2.0, see LICENSE.txt and NOTICE.txt for more information.