Amazon Cognito를 사용하여 미인증 게스트의 애플리케이션 액세스 허용
프런트엔드 SDK와 직접 HTTPS 요청 모두에서 AWS Identity and Access Management(IAM)을 직접 사용하는 대신 Amazon Cognito 인증을 사용할 수 있습니다.
다음과 같은 이유로 이 인증 형식을 사용하는 것이 좋습니다.
-
인증되지 않은 사용자 – 익명 사용자가 있는 웹 사이트가 있는 경우 Amazon Cognito 자격 증명 풀을 사용할 수 있습니다. 자세한 내용은 Amazon Cognito를 사용하여 미인증 게스트의 애플리케이션 액세스 허용 섹션을 참조하세요.
-
자체 인증 – 자체 인증 프로세스를 사용하거나 여러 인증 방법을 결합하려는 경우 Amazon Cognito 페더레이션 ID를 사용할 수 있습니다. 자세한 내용은 Amazon Cognito 개발자 안내서의 페더레이션 ID 시작하기를 참조하세요.
Amazon Cognito는 웹 및 모바일 앱에 대한 인증, 권한 부여 및 사용자 관리를 제공합니다. Amazon Location과 함께 Amazon Cognito 비인증 자격 증명 풀을 애플리케이션에서 범위가 축소된 임시 AWS자격 증명을 검색하는 방법으로 사용할 수 있습니다.
자세한 내용은 Amazon Cognito 개발자 안내서의 사용자 풀 시작하기를 참조하세요.
참고
모바일 개발자를 위해 Amazon Location은 iOS 및 Android 모두에 모바일 인증 SDK를 제공합니다. 자세한 내용은 다음 GitHub 리포지토리를 참조하세요.
Amazon Cognito 자격 증명 풀 생성
Amazon Cognito 자격 증명 풀을 만들어 인증되지 않은 게스트가 Amazon Cognito 콘솔AWS CLI 또는 Amazon Cognito API를 통해 애플리케이션에 액세스하는 것을 허용할 수 있습니다.
중요
생성하는 풀은 사용 중인 Amazon Location Service AWS 계정 리소스와 동일한 AWS 리전에 있어야 합니다.
인증되지 않은 자격 증명 역할과 관련된 IAM 정책을 다음 작업에 사용할 수 있습니다.
-
geo:GetMap*
-
geo:SearchPlaceIndex*
-
geo:GetPlace
-
geo:CalculateRoute*
-
geo:GetGeofence
-
geo:ListGeofences
-
geo:PutGeofence
-
geo:BatchDeleteGeofence
-
geo:BatchPutGeofence
-
geo:BatchEvaluateGeofences
-
geo:GetDevicePosition*
-
geo:ListDevicePositions
-
geo:BatchDeleteDevicePositionHistory
-
geo:BatchGetDevicePosition
-
geo:BatchUpdateDevicePosition
다른 Amazon Location 작업을 포함해도 효과가 없으며 인증되지 않은 ID는 해당 작업을 호출할 수 없습니다.
Amazon Cognito 콘솔을 사용하여 자격 증명 풀을 만들려면
-
Amazon Cognito 콘솔
로 이동합니다. -
자격 증명 풀 관리를 선택합니다.
-
새 자격 증명 풀 생성을 선택한 다음 자격 증명 풀의 이름을 입력합니다.
-
축소 가능한 인증되지 않은 자격 증명 섹션에서 인증되지 않은 자격 증명에 대한 액세스 활성화를 선택합니다.
-
풀 생성을 선택합니다.
-
자격 증명 풀에서 사용하려는 IAM 역할을 선택합니다.
-
세부 정보 보기를 확장합니다.
-
인증되지 않은 ID에서 역할 이름을 입력합니다.
-
정책 문서 보기 섹션을 확장한 다음, 정책을 추가하기 위해 편집을 선택합니다.
-
정책을 추가하여 리소스에 대한 액세스 권한을 부여합니다.
다음은 맵, 장소, 트래커 및 경로에 대한 정책 예시입니다. 자체 정책에 대한 예를 사용하려면
지역
및accountID
플레이스홀더를 교체하세요:참고
인증되지 않은 자격 증명 풀은 보안되지 않은 인터넷 사이트에 노출되기 위한 것이지만, 이러한 자격 증명 풀은 기간 제한이 있는 표준 AWS 자격 증명으로 교환된다는 점에 유의하세요.
인증되지 않은 자격 증명 풀과 관련된 IAM 역할의 범위를 적절하게 지정하는 것이 중요합니다.
-
허용를 선택하여 자격 증명 풀을 생성하세요.
결과 자격 증명 풀은 <
문법을 따릅니다. region
>:<GUID
>.
예:
us-east-1:1sample4-5678-90ef-aaaa-1234abcd56ef
Amazon Location과 관련된 추가 정책 예는 Amazon Location Service의 자격 증명 기반 정책 예제을 참조하세요.
JavaScript에서 Amazon Cognito ID 풀 사용
다음 예제에서는 생성한 인증되지 않은 자격 증명 풀을 자격 증명으로 교환한 다음 이 자격 증명을 사용하여 맵 리소스 ExampleMap
의 스타일 설명자를 가져오는 데 사용합니다.
const AWS = require("aws-sdk"); const credentials = new AWS.CognitoIdentityCredentials({ IdentityPoolId: "<identity pool ID>" // for example, us-east-1:1sample4-5678-90ef-aaaa-1234abcd56ef }); const client = new AWS.Location({ credentials, region: AWS.config.region || "<region>" }); console.log(await client.getMapStyleDescriptor("
ExampleMap
").promise());
참고
인증되지 않은 ID에서 검색한 자격 증명은 1시간 동안 유효합니다.
다음은 자격 증명이 만료되기 전에 자격 증명을 자동으로 갱신하는 함수의 예입니다.
async function refreshCredentials() { await credentials.refreshPromise(); // schedule the next credential refresh when they're about to expire setTimeout(refreshCredentials, credentials.expireTime - new Date()); }
이 작업을 간소화하기 위해 Amazon Location JavaScript 인증 도우미을 사용할 수 있습니다. 이는 자격 증명을 가져오고 새로 고치는 작업을 모두 대신합니다. 이 예제에서는 JavaScript v3용 AWS SDK를 사용합니다.
import { LocationClient, GetMapStyleDescriptorCommand } from "@aws-sdk/client-location"; import { withIdentityPoolId } from "@aws/amazon-location-utilities-auth-helper"; const identityPoolId = "<identity pool ID>"; // for example, us-east-1:1sample4-5678-90ef-aaaa-1234abcd56ef // Create an authentication helper instance using credentials from Cognito const authHelper = await withIdentityPoolId(identityPoolId); const client = new LocationClient({ region: "<region>", // The region containing both the identity pool and tracker resource ...authHelper.getLocationClientConfig(), // Provides configuration required to make requests to Amazon Location }); const input = { MapName: "ExampleMap", }; const command = new GetMapStyleDescriptorCommand(input); console.log(await client.send(command));
다음 단계
-
역할을 수정하려면 IAM 콘솔
로 이동하세요. -
자격 증명 풀을 관리하려면 Amazon Cognito 콘솔
로 이동하세요.