View a markdown version of this page

AWS 服務使用臨時登入資料存取 - Amazon Cognito

本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。

AWS 服務使用臨時登入資料存取

使用身分集區成功進行身分驗證的結果是一組AWS登入資料。透過這些登入資料,您的應用程式可以向受 IAM 身分驗證保護AWS的資源提出請求。使用您可以新增至應用程式以存取身分集區 API 操作的各種 AWSSDKs,您可以提出未驗證的 API 請求來產生臨時登入資料。然後,您可以將其他 SDKs AWS 服務新增至用戶端,並使用這些臨時登入資料簽署請求。授予臨時憑證角色的 IAM 許可必須允許您從其他 服務請求的操作。

在您設定 Amazon Cognito 登入資料提供者並擷取AWS登入資料後,請建立 AWS 服務用戶端。以下是 AWSSDK 文件的一些範例。

AWS用於建立用戶端的 SDK 資源

下列程式碼片段會初始化 Amazon DynamoDB 用戶端:

若要在 Android 應用程式中使用 Amazon Cognito 身分集區,請設定 AWS Amplify。如需詳細資訊,請參閱《Amplify 開發人員中心》中的身分驗證

// Create a service client with the provider AmazonDynamoDB client = new AmazonDynamoDBClient(credentialsProvider);

登入資料提供者會與 Amazon Cognito 通訊,同時擷取已驗證和未驗證使用者的唯一識別符,以及 AWSMobile SDK 的臨時、有限權限AWS登入資料。所擷取的登入資料有效期限為 1 小時,當其過期時,供應商會將其重新整理。

若要在 iOS 應用程式中使用 Amazon Cognito 身分集區,請設定 AWS Amplify。如需詳細資訊,請參閱《Amplify 開發人員中心》中的 Swift 身分驗證Flutter 身分驗證

// create a configuration that uses the provider AWSServiceConfiguration *configuration = [AWSServiceConfiguration configurationWithRegion:AWSRegionUSEast1 provider:credentialsProvider]; // get a client with the default service configuration AWSDynamoDB *dynamoDB = [AWSDynamoDB defaultDynamoDB];

登入資料提供者會與 Amazon Cognito 通訊,同時擷取已驗證和未驗證使用者的唯一識別符,以及 AWSMobile SDK 的臨時、有限權限AWS登入資料。所擷取的登入資料有效期限為 1 小時,當其過期時,供應商會將其重新整理。

若要在 iOS 應用程式中使用 Amazon Cognito 身分集區,請設定 AWS Amplify。如需詳細資訊,請參閱《Amplify 開發人員中心》中的 Swift 身分驗證

// get a client with the default service configuration let dynamoDB = AWSDynamoDB.default() // get a client with a custom configuration AWSDynamoDB.register(with: configuration!, forKey: "USWest2DynamoDB"); let dynamoDBCustom = AWSDynamoDB(forKey: "USWest2DynamoDB")

登入資料提供者會與 Amazon Cognito 通訊,同時擷取已驗證和未驗證使用者的唯一識別符,以及 AWSMobile SDK 的臨時、有限權限AWS登入資料。所擷取的登入資料有效期限為 1 小時,當其過期時,供應商會將其重新整理。

// Create a service client with the provider var dynamodb = new AWS.DynamoDB({region: 'us-west-2'});

登入資料提供者會與 Amazon Cognito 通訊,同時擷取已驗證和未驗證使用者的唯一識別符,以及 AWSMobile SDK 的臨時、有限權限AWS登入資料。所擷取的登入資料有效期限為 1 小時,當其過期時,供應商會將其重新整理。

AWS SDK for Unity 現在是 適用於 .NET 的 SDK 的一部分。若要在 中開始使用 Amazon Cognito適用於 .NET 的 SDK,請參閱《 適用於 .NET 的 AWS SDK開發人員指南》中的 Amazon Cognito 登入資料提供者。或者,請參閱 Amplify 開發中心,了解使用 建置應用程式的選項AWS Amplify。

// create a service client that uses credentials provided by Cognito AmazonDynamoDBClient client = new AmazonDynamoDBClient(credentials, REGION);

登入資料提供者會與 Amazon Cognito 通訊,同時擷取已驗證和未驗證使用者的唯一識別符,以及 AWSMobile SDK 的臨時、有限權限AWS登入資料。所擷取的登入資料有效期限為 1 小時,當其過期時,供應商會將其重新整理。

AWS SDK for Xamarin 現在是 適用於 .NET 的 SDK 的一部分。若要在 中開始使用 Amazon Cognito適用於 .NET 的 SDK,請參閱《 適用於 .NET 的 AWS SDK開發人員指南》中的 Amazon Cognito 登入資料提供者。或者,請參閱 Amplify 開發中心,了解使用 建置應用程式的選項AWS Amplify。

// create a service client that uses credentials provided by Cognito var client = new AmazonDynamoDBClient(credentials, REGION)

登入資料提供者會與 Amazon Cognito 通訊,同時擷取已驗證和未驗證使用者的唯一識別符,以及 AWSMobile SDK 的臨時、有限權限AWS登入資料。所擷取的登入資料有效期限為 1 小時,當其過期時,供應商會將其重新整理。