기계 번역으로 제공되는 번역입니다. 제공된 번역과 원본 영어의 내용이 상충하는 경우에는 영어 버전이 우선합니다.
인증되지 않은 사용자를 인증된 사용자로 전환
Amazon Cognito 자격 증명 풀은 인증된 사용자와 인증되지 않은 사용자를 모두 지원합니다. 인증되지 않은 사용자는 자격 증명 공급자(IdPs로 로그인하지 않은 경우에도 AWS 리소스에 액세스할 수 있습니다. 이러한 수준의 액세스는 사용자가 로그인하기 전에 사용자에게 콘텐츠를 표시하는 데 유용합니다. 인증되지 않은 각 사용자는 개별적으로 로그인 및 인증되지 않았더라도 자격 증명 풀에 고유한 자격 증명이 있습니다.
이 섹션에서는 사용자가 인증되지 않은 자격 증명으로 로그인하는 것에서 인증된 자격 증명을 사용하는 것으로 전환하는 경우를 설명합니다.
Android
사용자는 애플리케이션에 인증되지 않은 게스트로 로그인할 수 있습니다. 결국 지원되는 IdPs. Amazon Cognito는 이전 자격 증명이 새 자격 증명과 동일한 고유 식별자를 유지하고, 프로파일 데이터가 자동으로 병합되도록 합니다.
IdentityChangedListener 인터페이스의 프로파일 병합을 통해 애플리케이션에 알립니다. 인터페이스에 identityChanged 메서드를 구현하여 이러한 메시지를 수신할 수 있습니다.
@override public void identityChanged(String oldIdentityId, String newIdentityId) { // handle the change }
iOS - Objective-C
사용자는 애플리케이션에 인증되지 않은 게스트로 로그인할 수 있습니다. 결국 지원되는 IdPs. Amazon Cognito는 이전 자격 증명이 새 자격 증명과 동일한 고유 식별자를 유지하고, 프로파일 데이터가 자동으로 병합되도록 합니다.
NSNotificationCenter는 애플리케이션에 프로파일 병합을 알립니다.
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(identityIdDidChange:) name:AWSCognitoIdentityIdChangedNotification object:nil]; -(void)identityDidChange:(NSNotification*)notification { NSDictionary *userInfo = notification.userInfo; NSLog(@"identity changed from %@ to %@", [userInfo objectForKey:AWSCognitoNotificationPreviousId], [userInfo objectForKey:AWSCognitoNotificationNewId]); }
iOS - Swift
사용자는 애플리케이션에 인증되지 않은 게스트로 로그인할 수 있습니다. 결국 지원되는 IdPs. Amazon Cognito는 이전 자격 증명이 새 자격 증명과 동일한 고유 식별자를 유지하고, 프로파일 데이터가 자동으로 병합되도록 합니다.
NSNotificationCenter는 애플리케이션에 프로파일 병합을 알립니다.
[NSNotificationCenter.defaultCenter().addObserver(observer: self selector:"identityDidChange" name:AWSCognitoIdentityIdChangedNotification object:nil) func identityDidChange(notification: NSNotification!) { if let userInfo = notification.userInfo as? [String: AnyObject] { print("identity changed from: \(userInfo[AWSCognitoNotificationPreviousId]) to: \(userInfo[AWSCognitoNotificationNewId])") } }
JavaScript
처음에 인증되지 않은 사용자
사용자는 일반적으로 인증되지 않은 역할로 시작합니다. 이 역할의 경우 logins 속성 없이 fromCognitoIdentityPool 자격 증명 공급자를 생성하여 서비스 클라이언트에 연결합니다. 이 경우, 기본 구성은 다음과 같을 수 있습니다.
import { fromCognitoIdentityPool } from "@aws-sdk/credential-providers"; // Create a credentials provider without a logins map for the unauthenticated role. const region = "us-east-1"; const credentials = fromCognitoIdentityPool({ identityPoolId: "us-east-1:1699ebc0-7900-4099-b910-2df94f52a030", clientConfig: { region } }); // Attach the provider to each service client that needs credentials. const client = new SomeServiceClient({ region, credentials });
인증된 사용자로 전환
인증되지 않은 사용자가 IdP에 로그인하고 토큰이 있는 경우 토큰이 포함된 logins 맵으로 새 fromCognitoIdentityPool 공급자를 생성하는 사용자 지정 함수를 호출하여 사용자를 인증되지 않음에서 인증됨으로 전환할 수 있습니다.
// Called when an identity provider has a token for a logged in user function userLoggedIn(providerName, token) { // Re-create the provider with a logins map to switch to the authenticated role. const credentials = fromCognitoIdentityPool({ identityPoolId: "us-east-1:1699ebc0-7900-4099-b910-2df94f52a030", logins: { [providerName]: token }, clientConfig: { region } }); // Re-create any service clients so they pick up the new credentials. // SomeServiceClient is a placeholder: import the client for the service you're calling // (for example, S3Client from @aws-sdk/client-s3). const client = new SomeServiceClient({ region, credentials }); }
fromCognitoIdentityPool 공급자가 각 서비스 클라이언트에 직접 연결되므로 인증되지 않은 역할에서 인증된 역할로 전환하면 logins 맵을 사용하여 새 공급자를 생성하고 나중에 생성하는 모든 서비스 클라이언트에 전달해야 합니다. AWS SDK for JavaScript v2와 달리 v3 SDK는 글로벌 구성 객체를 사용하지 않으므로 재설정할 공유 자격 증명이 없습니다.
fromCognitoIdentityPool 공급자에 대한 자세한 내용은 AWS SDK for JavaScript v3 보안 인증 공급자를 참조하세요.