AWS 服務 使用臨時憑證存取 - Amazon Cognito

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

AWS 服務 使用臨時憑證存取

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

設定 Amazon Cognito 憑證提供者並擷取 AWS 憑證後,請建立 AWS 服務 用戶端。以下是文件的一些範例 AWS SDK。

AWS SDK 建立用戶端的資源

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

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

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

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

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

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

AWS SDK for Unity 現在是 的一部分AWS SDK for .NET。若要在 中開始使用 Amazon Cognito AWS SDK for .NET,請參閱 AWS SDK for .NET 開發人員指南中的 Amazon Cognito 憑證提供者。或者,請參閱 Amplify Dev Center 以取得使用 建置應用程式的選項 AWS Amplify。

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

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

AWS SDK for Xamarin 現在是 的一部分AWS SDK for .NET。若要在 中開始使用 Amazon Cognito AWS SDK for .NET,請參閱 AWS SDK for .NET 開發人員指南中的 Amazon Cognito 憑證提供者。或者,請參閱 Amplify Dev Center 以取得使用 建置應用程式的選項 AWS Amplify。

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

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