如何將多區域和多帳戶的 Amazon Cognito 使用者集區與 Amazon Cognito 身分集區整合?

1 分的閱讀內容
0

當 Amazon Cognito 使用者集區與 Amazon Cognito 身分集區位於不同的帳戶時,我需要將它們整合在一起。

簡短描述

當使用者登入您的應用程式時,Amazon Cognito 會驗證登入資訊。成功登入後,Amazon Cognito 使用者集區會建立工作階段,並將 ID、存取權和重新整理權杖傳回給已驗證的使用者。

Amazon Cognito 身分集區可為未驗證的訪客使用者和從支援的身分提供者 (IdP) 接收權杖的已驗證使用者提供臨時 AWS 憑證。使用這些 AWS 憑證,您的應用程式可以安全地存取 AWS 服務。

您可以將 Amazon Cognito 使用者集區與位於不同 AWS 帳戶的 Amazon Cognito 身分集區整合。透過此設定,您的使用者會從一個帳戶中的使用者集區進行驗證。然後,若要存取 AWS 服務,您的使用者會使用從另一個帳戶的身分集區取得的臨時 AWS 憑證。

解決方案

下列跨帳戶案例為範例組態。

Amazon Cognito 使用者集區位於美國東部 (維吉尼亞北部) AWS 區域的帳戶 A 中。Amazon Cognito 身分集區位於亞太區域 (孟買) 區域的帳戶 B 中。

在這個案例中,您必須從帳戶 B 身分集區取得臨時憑證,供使用者使用帳戶 A 使用者集區進行驗證。您必須將帳戶 A 使用者集區做為驗證提供者新增至帳戶 B 身分集區。

若要將使用者集區新增為驗證提供者,請依照下列步驟執行:

1.    在帳戶 A 中開啟新的 Amazon Cognito 主控台

2.    選擇 User Pools (使用者集區),然後從清單中選擇適當的使用者集區。

3.    複製並從外部保存使用者集區 ID應用程式用戶端 ID 的值。

作為驗證提供者的使用者集區範例:

帳戶 A 使用者集區
**使用者集區 ID:**us-east-1_xxxxxxxxx
**應用程式用戶端 ID:**79i7hhxxxxxxxx1d5iciiu7

4.    在帳戶 B 中開啟新的 Amazon Cognito 主控台,然後選擇 Federated identities (聯合身分)。

5.    從身分集區清單中,選擇適當的身分集區。

6.    選擇 Edit identity pool (編輯身分集區)。Edit identity pool (編輯身分集區) 頁面隨即出現。

7.    向下捲動並選擇 Authentication providers (驗證提供者) 以顯示驗證提供者選項。

8.    對於 User pool ID (使用者集區 ID),貼上您先前複製的使用者集區 ID。

9.    對於 App client id (應用程式用戶端 ID),貼上您之前複製的應用程式用戶端 ID。

10.    儲存您的變更。

呼叫 UpdateIdentityPool API,將使用者集區新增為驗證提供者。

範例 update-identity-pool 命令:

aws cognito-identity update-identity-pool --identity-pool-id example_identity_pool_id --identity-pool-name example_identity_pool_name --no-allow-unauthenticated-identities --cognito-identity-providers ProviderName=cognito-idp.example_region.amazonaws.com/example_user_pool_id,ClientId=example_app_client_id,ServerSideTokenCheck=false --region example_region

update-identity-pool 命令的描述:

  • example_identity_pool_id 對應於帳戶 B 中的身分集區 ID。範例:ap-south-1:12345678-abcd-abcd-abcd-1234567890ab。
  • example_app_client_id 代表來自帳戶 A 的用戶端 ID。範例:79i7hhxxxxxxxx1d5iciiu7。
  • example_region 代表身份集區的區域。範例:ap-south-1。
  • example_identity_pool_name 對應身分集區名稱。範例:test-pool。
  • example_user_pool_id 代表來自帳戶 A 的使用者集區。範例:us-east-1_xxxxxxxxx。

**重要:**由於 UpdateIdentityPool API 會重新設定身分集區的現有組態,因此請先呼叫 DescribeIdentityPool API。然後,將所有現有的身分集區參數傳送至 UpdateIdentityPool API。


AWS 官方
AWS 官方已更新 1 年前