

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

# Amazon Cognito를 사용하여 인증
<a name="authenticating-using-cognito"></a>

프런트엔드 SDK 요청과 함께 AWS Identity and Access Management (IAM) 사용자를 직접 사용하는 대신 Amazon Cognito 인증을 사용할 수 있습니다.

Amazon Cognito는 웹 및 모바일 앱에 대한 인증, 권한 부여 및 사용자 관리를 제공합니다. 애플리케이션이 범위가 축소된 임시 AWS 자격 증명을 검색하는 방법으로 Amazon Location과 함께 Amazon Cognito 인증되지 않은 자격 증명 풀을 사용할 수 있습니다.

자세한 내용은 *Amazon Cognito 개발자 안내서*의 [사용자 풀 시작하기](https://docs.aws.amazon.com/cognito/latest/developerguide/getting-started-user-pools.html)를 참조하세요.

다음과 같은 이유로 이 인증 형식을 사용하는 것이 좋습니다.
+ **인증되지 않은 사용자** – 익명 사용자가 있는 웹 사이트가 있는 경우 Amazon Cognito 자격 증명 풀을 사용할 수 있습니다.

  자세한 내용은 [Amazon Cognito를 사용하여 인증](#authenticating-using-cognito) 섹션을 참조하세요.
+ **자체 인증** – 자체 인증 프로세스를 사용하거나 여러 인증 방법을 결합하려는 경우 Amazon Cognito 페더레이션 ID를 사용할 수 있습니다.

  자세한 내용은 *Amazon Cognito 개발자 안내서*의 [페더레이션 ID 시작하기](https://docs.aws.amazon.com/cognito/latest/developerguide/getting-started-with-identity-pools.html)를 참조하세요.

## Amazon Cognito 및 Amazon Location Service 사용
<a name="cognito-and-location"></a>

인증되지 않은 자격 증명 역할과 연결된 AWS Identity and Access Management (IAM) 정책을 다음 작업과 함께 사용할 수 있습니다.

------
#### [ Maps ]

맵 작업의 목록
+ `geo-maps:GetStaticMap`
+ `geo-maps:GetTile`

**참고**  
위 작업의 리소스 이름은 다음과 같습니다.  

```
arn:aws:geo-maps:region::provider/default
```

------
#### [ Places ]

장소 작업의 목록:
+ `geo-places:Geocode`
+ `geo-places:ReverseGeocode`
+ `geo-places:SearchNearby`
+ `geo-places:SearchText`
+ `geo-places:Autocomplete`
+ `geo-places:Suggest`
+ `geo-places:GetPlace`

**참고**  
위 작업의 리소스 이름은 다음과 같습니다.  

```
arn:aws:geo-places:region::provider/default
```

------
#### [ Routes ]

경로 작업의 목록:
+ `geo-routes:CalculateRoutes`
+ `geo-routes:CalculateRouteMatrix`
+ `geo-routes:CalculateIsolines`
+ `geo-routes:OptimizeWaypoints`
+ `geo-routes:SnapToRoads`

**참고**  
위 작업의 리소스 이름은 다음과 같습니다.  

```
arn:aws:geo-routes:region::provider/default
```

------
#### [ Geofences and Trackers ]

지오펜스 및 트래커 작업의 목록
+ `geo:GetGeofence`
+ `geo:ListGeofences`
+ `geo:PutGeofence`
+ `geo:BatchDeleteGeofence`
+ `geo:BatchPutGeofence`
+ `geo:BatchEvaluateGeofences`
+ `geo:GetDevicePosition*`
+ `geo:ListDevicePositions`
+ `geo:BatchDeleteDevicePositionHistory`
+ `geo:BatchGetDevicePosition`
+ `geo:BatchUpdateDevicePosition`

**참고**  
위 작업의 리소스 이름은 다음과 같습니다.  

```
arn:aws:geo:region:accountID:tracker/ExampleTracker
```

------
#### [ Previous version ]

이전 버전 작업의 목록:
+ `geo:GetMap*`
+ `geo:SearchPlaceIndexForText`
+ `geo:SearchPlaceIndexForPosition`
+ `geo:GetPlace`
+ `geo:CalculateRoute`
+ `geo:CalculateRouteMatrix`

**참고**  
위 작업의 리소스 이름은 다음과 같습니다.  
**Maps**  

```
arn:aws:geo:region:accountID:map/ExampleMap
```
**Places**  

```
arn:aws:geo:region:accountID:place-index/ExamplePlaceIndex
```
**Routes**  

```
arn:aws:geo:region:accountID:route-calculator/ExampleCalculator
```

------

## Amazon Cognito ID 풀 생성
<a name="cognito-create-user-pool"></a>

Amazon Cognito 자격 증명 풀을 생성하여 Amazon Cognito 콘솔 AWS CLI, 또는 Amazon Cognito Amazon Cognito APIs를 통해 인증되지 않은 게스트가 애플리케이션에 액세스할 수 있도록 할 수 있습니다.

**중요**  
생성하는 풀은 사용 중인 Amazon Location Service 리소스와 동일한 AWS 계정 및 AWS 리전에 있어야 합니다.

------
#### [ Console ]

**Amazon Cognito 콘솔을 사용하여 자격 증명 풀을 만들려면**

1. [Amazon Cognito 콘솔](https://console.aws.amazon.com/cognito/home)로 이동합니다.

1. **자격 증명 풀 관리**를 선택합니다.

1. **새 자격 증명 풀 생성**을 선택한 다음 ID 풀의 이름을 입력합니다.

1. 축소 가능한 **인증되지 않은 자격 증명** 섹션에서 **인증되지 않은 자격 증명에 대한 액세스 활성화**를 선택합니다.

1. **풀 생성**을 선택합니다.

1. ID 풀에서 사용하려는 IAM 역할을 선택합니다.

1. **세부 정보 보기**를 확장합니다.

1. **인증되지 않은 ID**에서 역할 이름을 입력합니다.

1. **정책 문서 보기** 섹션을 확장한 다음, 정책을 추가하기 위해 **편집**을 선택합니다.

1. 정책을 추가하여 리소스에 대한 액세스 권한을 부여합니다.
**참고**  
작업 목록은 위의 [Amazon Cognito 및 Amazon Location Service 사용](#cognito-and-location) 섹션을 참조하세요.

   ```
   {
     "Version": "2012-10-17",		 	 	 
     "Statement": [
       {
     Sid": "RoutesReadOnly",
     Effect": "Allow",
     Action": [
           // add comma separated value from the previous section
         ],
     Resource": "value from previous section"
       }
     ]
   }
   ```

1. **허용**를 선택하여 ID 풀을 생성하세요.

------

## 웹에서 Amazon Cognito ID 풀 사용
<a name="identity-pool-js"></a>

다음 예제에서는 생성한 인증되지 않은 ID 풀을 자격 증명으로 교환한 다음 이 자격 증명을 사용하여 `CalculateIsolines`를 호출합니다. 이 작업을 단순화하기 위해 이 예제에서는 Amazon Location [인증 도우미 사용 방법](how-to-auth-helper.md) 프로시저를 사용합니다. 이는 자격 증명을 가져오고 새로 고치는 작업을 모두 대신합니다.

이 예제에서는 AWS SDK for JavaScript v3를 사용합니다.

```
import { GeoRoutesClient, CalculateIsolinesCommand , } from "@aws-sdk/client-geo-routes"; // ES Modules import
import { withIdentityPoolId } from "@aws/amazon-location-utilities-auth-helper";

const identityPoolId = "<identity pool ID>"; // for example, us-east-1:1sample4-5678-90ef-aaaa-1234abcd56ef

const authHelper = await withIdentityPoolId(identityPoolId);

const client = new GeoRoutesClient({
    ...authHelper.getClientConfig(),
    region: "<region>", // The region containing the identity pool
});

const input = {
    DepartNow: true,
    TravelMode: "Car",
    Origin: [-123.12327, 49.27531],
    Thresholds: {
        Time: [5, 10, 30],
    },
};

const command = new CalculateIsolinesCommand(input);
const response = await client.send(command);

console.log(JSON.stringify(response, null, 2))
```