

Die vorliegende Übersetzung wurde maschinell erstellt. Im Falle eines Konflikts oder eines Widerspruchs zwischen dieser übersetzten Fassung und der englischen Fassung (einschließlich infolge von Verzögerungen bei der Übersetzung) ist die englische Fassung maßgeblich.

# So verwenden Sie Authentifizierungshelfer
<a name="how-to-auth-helper"></a>

Dieser Abschnitt enthält zusätzliche Informationen zu Authentifizierungshelfern.

## Web
<a name="loc-sdk-auth-web"></a>

Die Amazon Location JavaScript Authentication Utilities helfen bei der Authentifizierung, wenn Amazon Location Service API-Aufrufe von JavaScript Anwendungen aus getätigt werden. Diese Dienstprogramme unterstützen speziell die Authentifizierung mithilfe von API-Schlüsseln oder Amazon Cognito.

**Installation**
+ Installieren Sie diese Bibliothek mit NPM:

  ```
  npm install @aws/amazon-location-utilities-auth-helper
  ```
+ Um sie direkt im Browser zu verwenden, fügen Sie Folgendes in Ihre HTML-Datei ein:

  ```
  <script src="https://cdn.jsdelivr.net/npm/@aws/amazon-location-utilities-auth-helper@1"></script>
  ```

### Usage
<a name="loc-sdk-auth-usage"></a>

Um die Authentifizierungshelfer zu verwenden, importieren Sie die Bibliothek und rufen Sie die erforderlichen Hilfsfunktionen auf. Diese Bibliothek unterstützt die Authentifizierung von Anfragen vom Amazon Location Service SDKs, einschließlich der eigenständigen [Apps Maps](https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/client/geo-maps/), [Places](https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/client/geo-places/) und [Routes](https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/client/geo-routes/) SDKs, sowie das Rendern von Karten mit [MapLibre GL JS](https://github.com/maplibre/maplibre-gl-js).

**Verwendung mit Modulen**

Dieses Beispiel demonstriert die Verwendung des eigenständigen Places SDK, um eine mit API-Schlüsseln authentifizierte Anfrage zu stellen:

```
npm install @aws-sdk/client-geo-places

import { GeoPlacesClient, GeocodeCommand } from "@aws-sdk/client-geo-places";
import { withAPIKey } from "@aws/amazon-location-utilities-auth-helper";

const authHelper = withAPIKey("<API Key>", "<Region>");
const client = new GeoPlacesClient(authHelper.getClientConfig());

const input = { ... };
const command = new GeocodeCommand(input);
const response = await client.send(command);
```

Dieses Beispiel demonstriert die Verwendung des eigenständigen Routes SDK, um eine mit API-Schlüsseln authentifizierte Anfrage zu stellen:

```
npm install @aws-sdk/geo-routes-client

import { GeoRoutesClient, CalculateRoutesCommand } from "@aws-sdk/geo-routes-client";
import { withAPIKey } from "@aws/amazon-location-utilities-auth-helper";

const authHelper = withAPIKey("<API Key>", "<Region>");
const client = new GeoRoutesClient(authHelper.getClientConfig());

const input = { ... };
const command = new CalculateRoutesCommand(input);
const response = await client.send(command);
```

In diesem Beispiel wird das Location SDK mit API-Schlüsselauthentifizierung verwendet:

```
npm install @aws-sdk/client-location

import { LocationClient, ListGeofencesCommand } from "@aws-sdk/client-location";
import { withAPIKey } from "@aws/amazon-location-utilities-auth-helper";

const authHelper = withAPIKey("<API Key>", "<Region>");
const client = new LocationClient(authHelper.getClientConfig());

const input = { ... };
const command = new ListGeofencesCommand(input);
const response = await client.send(command);
```

**Verwendung mit Browser**

Auf Hilfsfunktionen kann über das globale amazonLocationAuth Helper-Objekt zugegriffen werden, wenn sie direkt in einer Browserumgebung verwendet werden.

Dieses Beispiel zeigt eine Anfrage mit dem Amazon Location Client, die mithilfe von API-Schlüsseln authentifiziert wurde:

```
<script src="https://cdn.jsdelivr.net/npm/@aws/amazon-location-client@1"></script>

const authHelper = amazonLocationClient.withAPIKey("<API Key>", "<Region>");
const client = new amazonLocationClient.GeoRoutesClient(authHelper.getClientConfig());
const input = { ... };
const command = new amazonLocationClient.routes.CalculateRoutesCommand(input);
const response = await client.send(command);
```

Dieses Beispiel zeigt das Rendern einer Map mit MapLibre GL JS, authentifiziert mit einem API-Schlüssel:

```
<script src="https://cdn.jsdelivr.net/npm/maplibre-gl@5.x"></script>

const apiKey = "<API Key>";
const region = "<Region>";
const styleName = "Standard";

const map = new maplibregl.Map({
  container: "map",
  center: [-123.115898, 49.295868],
  zoom: 10,
  style: `https://maps.geo.${region}.amazonaws.com/v2/styles/${styleName}/descriptor?key=${apiKey}`,
});
```

Dieses Beispiel zeigt das Rendern einer Karte mit MapLibre GL JS mithilfe von Amazon Cognito:

```
<script src="https://cdn.jsdelivr.net/npm/maplibre-gl@5.x"></script>
<script src="https://cdn.jsdelivr.net/npm/@aws/amazon-location-utilities-auth-helper@1"></script>

const identityPoolId = "<Identity Pool ID>";
const authHelper = await amazonLocationAuthHelper.withIdentityPoolId(identityPoolId);

const map = new maplibregl.Map({
  container: "map",
  center: [-123.115898, 49.295868],
  zoom: 10,
  style: `https://maps.geo.${region}.amazonaws.com/v2/styles/${styleName}/descriptor`,
  ...authHelper.getMapAuthenticationOptions(),
});
```

**Alternative Verwendung mit authentifizierten Identitäten**

Sie können die withIdentityPool ID-Funktion so ändern, dass sie benutzerdefinierte Parameter für authentifizierte Identitäten enthält:

```
const userPoolId = "<User Pool ID>";

const authHelper = await amazonLocationAuthHelper.withIdentityPoolId(identityPoolId, {
  logins: {
    [`cognito-idp.${region}.amazonaws.com/${userPoolId}`]: "cognito-id-token"
  }
});
```

## iOS
<a name="loc-sdk-auth-ios"></a>

Das Amazon Location Service Mobile Authentication SDK for iOS hilft bei der Authentifizierung von Anfragen an Amazon Location Service APIs von iOS-Anwendungen. Es unterstützt speziell die Authentifizierung über API-Schlüssel oder Amazon Cognito.

**Installation**
+ Öffnen Sie Xcode und gehen Sie zu **Datei > Paketabhängigkeiten hinzufügen**.
+ Geben Sie die Paket-URL ([https://github.com/aws-geospatial/amazon-location-mobile-auth-sdk-ios/](https://github.com/aws-geospatial/amazon-location-mobile-auth-sdk-ios/)) in die Suchleiste ein und drücken Sie die Eingabetaste.
+ **Wählen Sie das Package "amazon-location-mobile-auth-sdk-ios“ aus und klicken Sie auf Paket hinzufügen.**
+ Wählen Sie das Paketprodukt "AmazonLocationiOSAuthSDK“ und klicken Sie auf **Package hinzufügen**.

### Usage
<a name="loc-sdk-auth-usage"></a>

Verwenden Sie nach der Installation der Bibliothek die `AuthHelper` Klasse, um Client-Einstellungen für API-Schlüssel oder Amazon Cognito zu konfigurieren.

**API-Schlüssel**

Hier ist ein Beispiel für die Verwendung des eigenständigen Places SDK mit API-Schlüsselauthentifizierung:

```
import AmazonLocationiOSAuthSDK
import AWSGeoPlaces

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

    let authHelper = try await AuthHelper.withApiKey(apiKey: apiKey, region: region)
    let client: GeoPlacesClient = GeoPlacesClient(config: authHelper.getGeoPlacesClientConfig())

    let input = AWSGeoPlaces.SearchTextInput(
        biasPosition: [-97.7457518, 30.268193],
        queryText: "tacos"
    )

    let output = try await client.searchText(input: input)
}
```

Hier ist ein Beispiel für die Verwendung des eigenständigen Routes SDK mit API-Schlüsselauthentifizierung:

```
import AmazonLocationiOSAuthSDK
import AWSGeoRoutes

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

    let authHelper = try await AuthHelper.withApiKey(apiKey: apiKey, region: region)
    let client: GeoRoutesClient = GeoRoutesClient(config: authHelper.getGeoRoutesClientConfig())

    let input = AWSGeoRoutes.CalculateRoutesInput(
        destination: [-123.1651031, 49.2577281],
        origin: [-97.7457518, 30.268193]
    )

    let output = try await client.calculateRoutes(input: input)
}
```

Hier ist ein Beispiel für die Verwendung des Location SDK mit API-Schlüsselauthentifizierung:

```
import AmazonLocationiOSAuthSDK
import AWSLocation

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

    let authHelper = try await AuthHelper.withApiKey(apiKey: apiKey, region: region)
    let client: LocationClient = LocationClient(config: authHelper.getLocationClientConfig())

    let input = AWSLocation.ListGeofencesInput(
        collectionName: "<Collection name>"
    )

    let output = try await client.listGeofences(input: input)
}
```

Hier ist ein Beispiel für die Verwendung des eigenständigen Places SDK mit Amazon Cognito:

```
import AmazonLocationiOSAuthSDK
import AWSGeoPlaces

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

    let authHelper = try await AuthHelper.withIdentityPoolId(identityPoolId: identityPoolId)
    let client: GeoPlacesClient = GeoPlacesClient(config: authHelper.getGeoPlacesClientConfig())

    let input = AWSGeoPlaces.SearchTextInput(
        biasPosition: [-97.7457518, 30.268193],
        queryText: "tacos"
    )

    let output = try await client.searchText(input: input)
}
```

Hier ist ein Beispiel für die Verwendung des eigenständigen Routes SDK mit Amazon Cognito:

```
import AmazonLocationiOSAuthSDK
import AWSGeoRoutes

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

    let authHelper = try await AuthHelper.withIdentityPoolId(identityPoolId: identityPoolId)
    let client: GeoRoutesClient = GeoRoutesClient(config: authHelper.getGeoRoutesClientConfig())

    let input = AWSGeoRoutes.CalculateRoutesInput(
        destination: [-123.1651031, 49.2577281],
        origin: [-97.7457518, 30.268193]
    )

    let output = try await client.calculateRoutes(input: input)
}
```

Hier ist ein Beispiel für die Verwendung des Location SDK mit Amazon Cognito:

```
import AmazonLocationiOSAuthSDK
import AWSLocation

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

    let authHelper = try await AuthHelper.withIdentityPoolId(identityPoolId: identityPoolId)
    let client: LocationClient = LocationClient(config: authHelper.getLocationClientConfig())

    let input = AWSLocation.ListGeofencesInput(
        collectionName: "<Collection name>"
    )

    let output = try await client.listGeofences(input: input)
}
```

## Android
<a name="loc-sdk-auth-android"></a>

Das Amazon Location Service Mobile Authentication SDK for Android unterstützt Sie bei der Authentifizierung von Anfragen an Amazon Location Service APIs von Android-Anwendungen aus und unterstützt insbesondere die Authentifizierung mit Amazon Cognito.

**Installation**
+ Dieses Authentifizierungs-SDK funktioniert mit dem gesamten AWS Kotlin-SDK. Beide SDKs werden in Maven Central veröffentlicht. Überprüfen Sie die neueste Version des [Auth-SDK](https://mvnrepository.com/artifact/software.amazon.location/auth) auf Maven Central.
+ Fügen Sie dem Abschnitt „Abhängigkeiten“ Ihrer `build.gradle` Datei in Android Studio die folgenden Zeilen hinzu:

  ```
  implementation("software.amazon.location:auth:1.1.0")
  implementation("org.maplibre.gl:android-sdk:11.5.2")
  implementation("com.squareup.okhttp3:okhttp:4.12.0")
  ```
+ Fügen Sie für die eigenständigen Maps, Places und Routes SDKs die folgenden Zeilen hinzu:

  ```
  implementation("aws.sdk.kotlin:geomaps:1.3.65")
  implementation("aws.sdk.kotlin:geoplaces:1.3.65")
  implementation("aws.sdk.kotlin:georoutes:1.3.65")
  ```
+ Fügen Sie für das konsolidierte Location SDK, das Geofencing und Tracking umfasst, die folgende Zeile hinzu:

  ```
  implementation("aws.sdk.kotlin:location:1.3.65")
  ```

### Usage
<a name="loc-sdk-auth-usage"></a>

Importieren Sie die folgenden Klassen in Ihren Code:

```
// For the standalone Maps, Places, and 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
import software.amazon.location.auth.LocationCredentialsProvider
import software.amazon.location.auth.AwsSignerInterceptor
import org.maplibre.android.module.http.HttpRequestUtil
import okhttp3.OkHttpClient
```

Sie können ein erstellen `AuthHelper` und es mit dem AWS Kotlin SDK verwenden:

**Beispiel: Credential Provider mit Identity Pool ID**

```
private suspend fun exampleCognitoLogin() {
    val authHelper = AuthHelper.withCognitoIdentityPool("MY-COGNITO-IDENTITY-POOL-ID", applicationContext)
    
    var geoMapsClient = GeoMapsClient(authHelper?.getGeoMapsClientConfig())
    var geoPlacesClient = GeoPlacesClient(authHelper?.getGeoPlacesClientConfig())
    var geoRoutesClient = GeoRoutesClient(authHelper?.getGeoRoutesClientConfig())
    
    var locationClient = LocationClient(authHelper?.getLocationClientConfig())
}
```

**Beispiel: Anmeldeinformationsanbieter mit benutzerdefiniertem Anmeldeinformationsanbieter**

```
private suspend fun exampleCustomCredentialLogin() {
    var authHelper = AuthHelper.withCredentialsProvider(MY-CUSTOM-CREDENTIAL-PROVIDER, "MY-AWS-REGION", applicationContext)

    var geoMapsClient = GeoMapsClient(authHelper?.getGeoMapsClientConfig())
    var geoPlacesClient = GeoPlacesClient(authHelper?.getGeoPlacesClientConfig())
    var geoRoutesClient = GeoRoutesClient(authHelper?.getGeoRoutesClientConfig())
    
    var locationClient = LocationClient(authHelper?.getLocationClientConfig())
}
```

**Beispiel: Anmeldeinformationsanbieter mit API-Schlüssel**

```
private suspend fun exampleApiKeyLogin() {
    var authHelper = AuthHelper.withApiKey("MY-API-KEY", "MY-AWS-REGION", applicationContext)

    var geoMapsClient = GeoMapsClient(authHelper?.getGeoMapsClientConfig())
    var geoPlacesClient = GeoPlacesClient(authHelper?.getGeoPlacesClientConfig())
    var geoRoutesClient = GeoRoutesClient(authHelper?.getGeoRoutesClientConfig())
    
    var locationClient = LocationClient(authHelper?.getLocationClientConfig())
}
```

Sie können es verwenden`LocationCredentialsProvider`, um die MapLibre Map zu laden. Ein Beispiel:

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

Verwenden Sie die erstellten Clients, um Amazon Location Service anzurufen. Hier ist ein Beispiel, das nach Orten in der Nähe eines bestimmten Breiten- und Längengrades sucht:

```
val suggestRequest = SuggestRequest {
       biasPosition = listOf(-97.718833, 30.405423)
       maxResults = MAX_RESULT
       language = "PREFERRED-LANGUAGE"
   }
val nearbyPlaces = geoPlacesClient.suggest(suggestRequest)
```