Amazon Cognito 보안 인증 공급자 - AWS SDK for .NET

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

Amazon Cognito 보안 인증 공급자

참고

이 항목의 정보는 .NET Framework 및 AWS SDK for .NET 버전 3.3 및 이전 버전을 기반으로 하는 프로젝트에만 해당됩니다.

Amazon.CognitoIdentity.CognitoAWSCredentials, 에 있습니다. AWSSDK CognitoIdentity NuGet패키지는 Amazon Cognito와 AWS Security Token Service (AWS STS) 를 사용하여 자격 증명을 검색하여 호출하는 AWS 자격 증명 객체입니다.

CognitoAWSCredentials 설정의 첫 번째 단계는 "자격 증명 풀"을 생성하는 것입니다. (자격 증명 풀은 계정에 관련된 사용자 자격 증명 정보의 저장소입니다. 정보는 클라이언트 플랫폼, 디바이스 및 운영 체제 간에 가져올 수 있어 사용자가 스마트폰에서 앱을 사용하다가 태블릿으로 전환하면 앱 정보가 해당 사용자에게 계속 제공됩니다. Amazon Cognito 콘솔에서 새로운 자격 증명 풀을 생성할 수 있습니다. 콘솔을 사용 중인 경우, 콘솔에서 사용자에게 필요한 다음과 같은 다른 정보 또한 제공합니다.

  • 계정 번호- A 12자리 숫자. 예: 123456789012 (사용자 계정에 고유한 숫자)

  • 인증되지 않은 역할 ARN- 인증되지 않은 사용자가 맡을 역할 예를 들어, 이 역할은 데이터에 대한 읽기 전용 권한을 제공할 수 있습니다.

  • 인증된 역할 ARN- 인증된 사용자가 맡을 역할 이 역할은 데이터에 대한 더 광범위한 권한을 제공할 수 있습니다.

Cognito 설정 AWSCredentials

다음 코드 예제에서는 인증되지 않은 사용자로 Amazon S3를 호출하는 데 사용할 수 있도록 CognitoAWSCredentials를 설정하는 방법을 보여줍니다. 이렇게 하면 사용자를 인증하기 위해 필요한 최소한의 데이터만으로도 호출할 수 있습니다. 사용자 권한은 역할에 의해 제어되므로 필요한 액세스를 구성할 수 있습니다.

CognitoAWSCredentials credentials = new CognitoAWSCredentials( accountId, // Account number identityPoolId, // Identity pool ID unAuthRoleArn, // Role for unauthenticated users null, // Role for authenticated users, not set region); using (var s3Client = new AmazonS3Client(credentials)) { s3Client.ListBuckets(); }

인증되지 않은 AWS 사용자로 사용

다음 코드 예제는 인증되지 않은 AWS 사용자로 사용을 시작한 다음 Facebook을 통해 인증하고 Facebook 자격 증명을 사용하도록 자격 증명을 업데이트하는 방법을 보여줍니다. 이 접근 방식을 사용하여 인증된 역할을 통해 인증된 사용자에게 다른 자격 증명을 부여할 수 있습니다. 예를 들어, 사용자가 익명으로 콘텐츠를 볼 수 있도록 허용하되 하나 이상의 구성된 공급자로 로그온한 경우에 게시할 수 있도록 허용하는 스마트폰 애플리케이션이 있을 수도 있습니다.

CognitoAWSCredentials credentials = new CognitoAWSCredentials( accountId, identityPoolId, unAuthRoleArn, // Role for unauthenticated users authRoleArn, // Role for authenticated users region); using (var s3Client = new AmazonS3Client(credentials)) { // Initial use will be unauthenticated s3Client.ListBuckets(); // Authenticate user through Facebook string facebookToken = GetFacebookAuthToken(); // Add Facebook login to credentials. This clears the current AWS credentials // and retrieves new AWS credentials using the authenticated role. credentials.AddLogin("graph.facebook.com", facebookAccessToken); // This call is performed with the authenticated role and credentials s3Client.ListBuckets(); }

CognitoAWSCredentials 객체는 AWS SDK for .NET의 일부인 AmazonCognitoSyncClient와 함께 사용하는 경우 훨씬 더 많은 기능을 제공합니다. AmazonCognitoSyncClientCognitoAWSCredentials를 모두 사용 중인 경우 IdentityPoolId로 호출할 때 IdentityIdAmazonCognitoSyncClient 속성을 지정하지 않아도 됩니다. 이러한 속성은 CognitoAWSCredentials에서 자동으로 채워집니다. 다음 코드 예에서는 이를 보여주고, 뿐만 아니라 IdentityId에 대한 CognitoAWSCredentials가 변경될 때마다 이를 알려주는 이벤트도 보여줍니다. IdentityId는 인증되지 않은 사용자에서 인증된 사용자로 변경될 때와 같은 일부 경우에 변경될 수 있습니다.

CognitoAWSCredentials credentials = GetCognitoAWSCredentials(); // Log identity changes credentials.IdentityChangedEvent += (sender, args) => { Console.WriteLine("Identity changed: [{0}] => [{1}]", args.OldIdentityId, args.NewIdentityId); }; using (var syncClient = new AmazonCognitoSyncClient(credentials)) { var result = syncClient.ListRecords(new ListRecordsRequest { DatasetName = datasetName // No need to specify these properties //IdentityId = "...", //IdentityPoolId = "..." }); }