

기계 번역으로 제공되는 번역입니다. 제공된 번역과 원본 영어의 내용이 상충하는 경우에는 영어 버전이 우선합니다.

# 인증 도우미 사용 방법
<a name="how-to-auth-helper"></a>

이 섹션에서는 인증 도우미에 대한 추가 정보를 제공합니다.

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

Amazon Location JavaScript 인증 유틸리티는 JavaScript 애플리케이션에서 Amazon Location Service API를 호출할 때 인증을 지원합니다. 이러한 유틸리티는 특히 API 키 또는 Amazon Cognito를 사용한 인증을 지원합니다.

**설치**
+ NPM을 사용하여 이 라이브러리를 설치합니다.

  ```
  npm install @aws/amazon-location-utilities-auth-helper
  ```
+ 브라우저에서 직접 사용하려면 HTML 파일에 다음을 포함합니다.

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

### 사용법
<a name="loc-sdk-auth-usage"></a>

인증 도우미를 사용하려면 라이브러리를 가져온 후 필요한 유틸리티 함수를 호출합니다. 이 라이브러리는 [Maps](https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/client/geo-maps/), [Places](https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/client/geo-places/) 및 [Routes](https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/client/geo-routes/) 독립형 SDK를 포함한 Amazon Location Service SDK의 요청 인증과 [MapLibre GL JS](https://github.com/maplibre/maplibre-gl-js)를 사용한 맵 렌더링을 지원합니다.

**모듈 사용**

이 예제에서는 독립형 Places SDK를 사용하여 API 키로 요청을 인증하는 방법을 보여줍니다.

```
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);
```

이 예제에서는 독립형 Routes SDK를 사용하여 API 키로 요청을 인증하는 방법을 보여줍니다.

```
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);
```

이 예제에서는 Location SDK를 API 키 인증과 함께 사용합니다.

```
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);
```

**브라우저에서 사용**

유틸리티 함수는 브라우저 환경에서 직접 사용할 때 amazonLocationAuthHelper 글로벌 객체에서 액세스할 수 있습니다.

이 예제에서는 API 키를 사용하여 인증된 Amazon Location Client에 대한 요청을 보여줍니다.

```
<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);
```

이 예제에서는 API 키를 사용하여 인증된 MapLibre GL JS로 맵을 렌더링하는 방법을 보여줍니다.

```
<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}`,
});
```

이 예제에서는 Amazon Cognito를 사용하여 MapLibre GL JS로 맵을 렌더링하는 방법을 보여줍니다.

```
<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(),
});
```

**인증된 자격 증명을 사용한 대체 사용**

인증된 자격 증명에 대한 사용자 지정 파라미터를 포함하도록 withIdentityPoolId 함수를 수정할 수 있습니다.

```
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>

iOS용 Amazon Location Service 모바일 인증 SDK는 iOS 애플리케이션에서 Amazon Location Service API에 대한 요청을 인증하는 데 도움이 됩니다. 특히 API 키 또는 Amazon Cognito를 통한 인증을 지원합니다.

**설치**
+ Xcode를 열고 **파일 > 패키지 종속성 추가**로 이동합니다.
+ 패키지 URL([https://github.com/aws-geospatial/amazon-location-mobile-auth-sdk-ios/](https://github.com/aws-geospatial/amazon-location-mobile-auth-sdk-ios/))를 검색 창에 입력하고 Enter를 누릅니다.
+ "amazon-location-mobile-auth-sdk-ios" 패키지를 선택하고 **패키지 추가**를 클릭합니다.
+ "AmazonLocationiOSAuthSDK" 패키지 제품을 선택하고 **패키지 추가**를 클릭합니다.

### 사용법
<a name="loc-sdk-auth-usage"></a>

라이브러리를 설치한 후 `AuthHelper` 클래스를 사용하여 API 키 또는 Amazon Cognito에 대한 클라이언트 설정을 구성합니다.

**API 키**

다음은 API 키 인증과 함께 독립형 Places SDK를 사용하는 예제입니다.

```
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)
}
```

다음은 API 키 인증과 함께 독립형 Routes SDK를 사용하는 예제입니다.

```
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)
}
```

다음은 API 키 인증과 함께 Location SDK를 사용하는 예제입니다.

```
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)
}
```

다음은 Amazon Cognito와 함께 독립형 Places SDK를 사용하는 예제입니다.

```
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)
}
```

다음은 Amazon Cognito와 함께 독립형 Routes SDK를 사용하는 예제입니다.

```
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)
}
```

다음은 Amazon Cognito와 함께 Location SDK를 사용하는 예제입니다.

```
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>

Android용 Amazon Location Service 모바일 인증 SDK는 Android 애플리케이션에서 Amazon Location Service API에 대한 요청을 인증하는 데 도움이 되며, 특히 Amazon Cognito를 사용한 인증을 지원합니다.

**설치**
+ 이 인증 SDK는 전체 AWS Kotlin SDK에서 작동합니다. 두 SDK는 Maven Central에 게시됩니다. Maven Central에서 [인증 SDK](https://mvnrepository.com/artifact/software.amazon.location/auth)의 최신 버전을 확인합니다.
+ Android Studio에서 `build.gradle` 파일의 종속성 섹션에 다음 줄을 추가합니다.

  ```
  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")
  ```
+ 독립형 Maps, Places 및 Routes SDK의 경우 다음 줄을 추가합니다.

  ```
  implementation("aws.sdk.kotlin:geomaps:1.3.65")
  implementation("aws.sdk.kotlin:geoplaces:1.3.65")
  implementation("aws.sdk.kotlin:georoutes:1.3.65")
  ```
+ 지오펜싱 및 추적이 포함된 통합 Location SDK의 경우 다음 줄을 추가합니다.

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

### 사용법
<a name="loc-sdk-auth-usage"></a>

코드에서 다음 클래스를 가져옵니다.

```
// 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
```

를 생성하고 AWS Kotlin SDK와 함께 `AuthHelper` 사용할 수 있습니다.

**예: 자격 증명 풀 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())
}
```

**예: 사용자 지정 자격 증명 공급자가 있는 자격 증명 공급자**

```
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())
}
```

**예: API 키가 있는 자격 증명 공급자**

```
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())
}
```

`LocationCredentialsProvider`를 사용하여 MapLibre 맵을 로드할 수 있습니다. 다음 예를 참고하세요

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

생성된 클라이언트를 사용하여 Amazon Location Service를 호출합니다. 다음은 지정된 위도 및 경도에 가까운 장소를 검색하는 예제입니다.

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