本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。
什麼是 Amazon Cognito?
Amazon Cognito 是適用於 Web 和行動應用程式的身分平台。是一種使用者目錄、身分驗證伺服器,以及 OAuth 2.0 存取權杖和 AWS 憑證的授權服務。使用 Amazon Cognito,您可以從內建的使用者目錄、企業目錄以及 Google 和 Facebook 等消費者身分提供者進行驗證和授權使用者。
主題
接下來兩個元件組成 Amazon Cognito。兩個元件會根據您對使用者的存取需求獨立或一併運作。
使用者集區
當您要對應用程式或 API 進行驗證和使用者授權時,請建立使用者集區。使用者集區是具有自助服務和管理員驅動的使用者建立、管理和驗證的使用者目錄。您的使用者集區可以是獨立的目錄和 OIDC 身分提供者 (IdP),也可以是第三方員工和客戶身分提供者的中繼服務提供者 (SP)。針對您組織在具使用者集區之 SAML 2.0 與 OIDC IdPs 中的人力身份,您可以在應用程式提供單一登入 (SSO)。針對您組織在公開 OAuth 2.0 身分儲存 Amazon、Google、Apple 和 Facebook 中的客戶身分,您也可以在應用程式提供 SSO。如需客戶身份與存取管理 (CIAM) 的更多資訊,請參閱 CIAM 是什麼?
使用者集區不需要與身分池整合。在使用者集區中,您可以將經過驗證的 JSON Web 權杖 (JWT) 直接發布至應用程式、Web 伺服器或 API。
身分集區
當您想要授權已驗證或匿名使用者存取您的 AWS 資源時,請設定 Amazon Cognito 身分池。身分池會為您的應用程式發布 AWS 憑證,以便為使用者提供資源。您可以使用受信任的身分提供者 (例如,使用者集區或 SAML 2.0 服務) 來驗證使用者。也可以選擇性地為訪客使用者發布憑證。身分池使用角色和屬性為基礎的存取控制,來管理使用者存取 AWS 資源的憑證。
身分池不需要與使用者集區整合。身分池可以直接從員工和消費者身分提供者接受經過驗證的宣告。
一併使用的 Amazon Cognito 使用者集區與身分池
在本主題開始的圖表中,您可以使用 Amazon Cognito 驗證您的使用者,然後授與他們存取 AWS 服務。
-
您的應用程式使用者會透過使用者集區登入,並收到 OAuth 2.0 權杖。
-
您的應用程式與身分池交換使用者集區權杖,取得臨時的 AWS 憑證,以用於 AWS API 和 AWS Command Line Interface (AWS CLI)。
-
您的應用程式會將憑證工作階段指派給您的使用者,並提供授權存取 AWS 服務,例如 Amazon S3 和 Amazon DynamoDB。
如需使用身分池和使用者集區的更多範例,請參閱 Amazon Cognito 常見案例。
Amazon Cognito,共同責任模型
Amazon Cognito 功能
使用者集區
Amazon Cognito 使用者集區是一種使用者目錄。透過使用者集區,您的使用者就可以透過 Amazon Cognito 登入 Web 或行動應用程式,或者透過第三方 IdP 以聯合身分登入。聯合和本機使用者在使用者集區中有一個使用者設定檔。
本機使用者是直接在使用者集區中註冊或建立的使用者。您可以在 AWS Management Console、AWS SDK 或 AWS Command Line Interface (AWS CLI) 中管理和自訂這些使用者設定檔。
Amazon Cognito 使用者集區接受來自第三方 IdP 的權杖和宣告,並收集使用者屬性到發布至應用程式的 JWT 中。您可以在一組 JWT 上標準化應用程式,而 Amazon Cognito 會處理與 IdPs 的互動,將其宣告映射至中央權杖格式。
Amazon Cognito 使用者集區可以是獨立的 IdP。Amazon Cognito 從 OpenID Connect (OIDC) 標準中提取,產生用於身分驗證和授權的 JWT。當您登入本機使用者時,您的使用者集區對這些使用者具有權威性。當您驗證本機使用者時,可以存取下列功能。
-
實作自己的網頁前端,該前端會呼叫 Amazon Cognito 使用者集區 API 來驗證、授權和管理您的使用者。
-
為使用者設定多重要素驗證 (MFA) Amazon Cognito 支援以時間為基礎的一次性密碼 (TOTP) 和 SMS 訊息 MFA。
-
防止受到惡意控制的使用者帳戶存取。
-
建立您自己的自訂多步驟身份驗證流程。
-
查詢其他目錄中的使用者,然後將其遷移到 Amazon Cognito。
Amazon Cognito 使用者集區也可以扮演雙重角色,既是 IdP 服務提供者 (SP) 也是應用程式執行 IdP。Amazon Cognito 使用者集區可以連接至消費者 IdP,如 Facebook 和 Google,或是生產力 IdP,如 Okta 和 Active Directory 同盟服務 (ADFS)。
使用 Amazon Cognito 使用者集區發布的 OAuth 2.0 和 OpenID Connect (OIDC) 權杖,您可以
-
在您的應用程式中接受對使用者進行身分驗證的 ID 權杖,並提供設定使用者設定檔所需的資訊
-
在您的 API 中接受具有授權使用者 API 呼叫 OIDC 範圍的存取權杖。
-
從 Amazon Cognito 身分池擷取 AWS 憑證。
功能 | 描述 |
---|---|
OIDC IdP | Issue ID tokens to authenticate users |
Authorization server | Issue access tokens to authorize user access to APIs |
SAML 2.0 SP | Transform SAML assertions into ID and access tokens |
OIDC SP | Transform OIDC tokens into ID and access tokens |
OAuth 2.0 SP | Transform ID tokens from Apple, Facebook, Amazon, or Google to your own ID and access tokens |
Authentication frontend service | Sign up, manage, and authenticate users with the hosted UI |
API support for your own UI | Create, manage and authenticate users through API requests in supported AWS SDKs¹ |
MFA | Use SMS messages, TOTPs, or your user's device as an additional authentication factor¹ |
Security monitoring & response | Secure against malicious activity and insecure passwords¹ |
Customize authentication flows | Build your own authentication mechanism, or add custom steps to existing flows¹ |
Groups | Create logical groupings of users, and a hierarchy of IAM role claims when you pass tokens to identity pools |
Customize ID tokens | Customize your ID tokens with new, modified, and suppressed claims |
Customize user attributes | Assign values to user attributes and add your own custom attributes |
¹ 功能僅適用於本機使用者。
如需使用者集區的詳細資訊,請參閱 使用者集區入門 和 Amazon Cognito 使用者集區 API 參考。
身分集區
身分池是您指派使用者或訪客唯一識別符或身分,並接收臨時授權 AWS 憑證的集合。當您以來自 SAML 2.0、OpenID Connect (OIDC) 或 OAuth 2.0 社交身分提供者 (IdP) 的受信任宣告形式向身分池提供驗證時,表示您將您的使用者與身分池中的身分建立關聯。身分池為身分建立的權杖,可以從 AWS Security Token Service (AWS STS) 檢索臨時工作階段憑證。
若要補充已驗證的身分,您還可以設定身分池在沒有 IdP 驗證的情況下授權 AWS 存取。您可以提供自己自訂的身分驗證,也可以不提供身分驗證。您可以使用未經驗證的身分向任何請求 AWS 憑證的應用程式使用者臨時授權。身分池也會接受宣告,並使用開發人員驗證身分,根據您自己的自訂結構描述發布憑證。
使用 Amazon Cognito 身分池,您可以透過兩種方式與您 AWS 帳戶 的 IAM 政策整合。您可以一起使用或單獨使用這兩項功能。
角色類型存取控制
當您的使用者將宣告傳遞至您的身分池時,Amazon Cognito 會選擇其請求的 IAM 角色。若要根據您的需求自訂角色許可,請將 IAM 政策套用至每個角色。例如,如果您的使用者證明他們位於行銷部門,則他們會收到角色憑證,其中包含針對行銷部門存取需求而量身打造的原則。Amazon Cognito 可以請求預設角色、根據查詢使用者宣告的規則來請求角色,或根據使用者集區中使用者群組成員資格請求角色。您也可以設定角色信任政策,讓 IAM 僅信任您的身分池來產生臨時工作階段。
存取控制的屬性
您的身分池會從使用者的宣告中讀取屬性,並將其映射至使用者臨時工作階段中的主要標籤。然後,您可以設定以 IAM 資源為基礎的政策,以從身分池中具有工作階段標籤的 IAM 主體允許或拒絕存取資源。例如,如果您的使用者證明他們位於行銷部門,AWS STS 會將他們的工作階段標記為 Department: marketing
。您的 Amazon S3 儲存貯體將根據 aws:PrincipalTag 條件允許讀取操作,該條件需要的 Department
標籤值為 marketing
。
功能 | 描述 |
---|---|
Amazon Cognito user pool SP | Exchange an ID token from your user pool for web identity credentials from AWS STS |
SAML 2.0 SP | Exchange SAML assertions for web identity credentials from AWS STS |
OIDC SP | Exchange OIDC tokens for web identity credentials from AWS STS |
OAuth 2.0 SP | Exchange OAuth tokens from Amazon, Facebook, Google, Apple, and Twitter for web identity credentials from AWS STS |
Custom SP | With AWS credentials, exchange claims in any format for web identity credentials from AWS STS |
Unauthenticated access | Issue limited-access web identity credentials from AWS STS without authentication |
Role-based access control | Choose an IAM role for your authenticated user based on their claims, and configure your roles to only be assumed in the context of your identity pool |
Attribute-based access control | Convert claims into principal tags for your AWS STS temporary session, and use IAM policies to filter resource access based on principal tags |
如需身分集區的詳細資訊,請參閱 Amazon Cognito 身分集區 (聯合身分) 入門 和 Amazon Cognito 身分集區 API 參考。
Amazon Cognito 使用者集區和身分池比較
功能 | 描述 | 使用者集區 | 身分集區 |
---|---|---|---|
OIDC IdP | Issue OIDC ID tokens to authenticate app users | ✓ | |
API authorization server | Issue access tokens to authorize user access to APIs, databases, and other resources that accept OAuth 2.0 authorization scopes | ✓ | |
IAM web identity authorization server | Generate tokens that you can exchange with AWS STS for temporary AWS credentials | ✓ | |
SAML 2.0 SP & OIDC IdP | Issue customized OIDC tokens based on claims from a SAML 2.0 IdP | ✓ | |
OIDC SP & OIDC IdP | Issue customized OIDC tokens based on claims from an OIDC IdP | ✓ | |
OAuth 2.0 SP & OIDC IdP | Issue customized OIDC tokens based on scopes from OAuth 2.0 social providers like Apple and Google | ✓ | |
SAML 2.0 SP & credentials broker | Issue temporary AWS credentials based on claims from a SAML 2.0 IdP | ✓ | |
OIDC SP & credentials broker | Issue temporary AWS credentials based on claims from an OIDC IdP | ✓ | |
OAuth 2.0 SP & credentials broker | Issue temporary AWS credentials based on scopes from OAuth 2.0 social providers like Apple and Google | ✓ | |
Amazon Cognito user pool SP & credentials broker | Issue temporary AWS credentials based on OIDC claims from an Amazon Cognito user pool | ✓ | |
Custom SP & credentials broker | Issue temporary AWS credentials based on developer IAM authorization | ✓ | |
Authentication frontend service | Sign up, manage, and authenticate users with the hosted UI | ✓ | |
API support for your own authentication UI | Create, manage and authenticate users through API requests in supported AWS SDKs¹ | ✓ | |
MFA | Use SMS messages, TOTPs, or your user's device as an additional authentication factor¹ | ✓ | |
Security monitoring & response | Protect against malicious activity and insecure passwords¹ | ✓ | |
Customize authentication flows | Build your own authentication mechanism, or add custom steps to existing flows¹ | ✓ | |
Groups | Create logical groupings of users, and a hierarchy of IAM role claims when you pass tokens to identity pools | ✓ | |
Customize ID tokens | Customize your ID tokens with new, modified, and suppressed claims | ✓ | |
AWS WAF web ACLs | Monitor and control requests to your authentication environment with AWS WAF | ✓ | |
Customize user attributes | Assign values to user attributes and add your own custom attributes | ✓ | |
Unauthenticated access | Issue limited-access web identity credentials from AWS STS without authentication | ✓ | |
Role-based access control | Choose an IAM role for your authenticated user based on their claims, and configure your roles to only be assumed in the context of your identity pool | ✓ | |
Attribute-based access control | Transform user claims into principal tags for your AWS STS temporary session, and use IAM policies to filter resource access based on principal tags | ✓ |
¹ 功能僅適用於本機使用者。
Amazon Cognito 入門
如需最常使用的任務以及如何開始的指南,請參閱 Amazon Cognito 入門。
如需影片、文章、文件和範例應用程式,請參閱 Amazon Cognito 開發人員資源
若要使用 Amazon Cognito,您需要一個 AWS 帳戶。如需更多詳細資訊,請參閱 使用 Amazon Cognito 主控台。
區域可用性
全球已有多個 AWS 區域可使用 Amazon Cognito。在每個區域中,Amazon Cognito 都會分佈在多個可用區域。這些可用區域各自實體隔離,但以私有、低延遲、高輸送量、高度冗餘的網路連線加以整合。這些可用區域讓 AWS 一方面可以提供極高可用性及備援能力的服務 (包括 Amazon Cognito),一方面可以將延遲降至最低。
如需可使用 Amazon Cognito 的所有區域清單,請參閱 Amazon Web Services 一般參考 中的 AWS 區域與端點。如需進一步了解各區域之可用區域數量的資訊,請參閱 AWS 全球基礎設施
Amazon Cognito 定價
如需 Amazon Cognito 定價的相關資訊,請參閱 Amazon Cognito 定價