本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。
什么是 Amazon Cognito?
Amazon Cognito 是 Web 和移动应用程序的身份平台。它是用户目录、身份验证服务器以及 OAuth 2.0 访问令牌和 Amazon 凭证的授权服务。使用 Amazon Cognito,您可以对内置用户目录、企业目录以及 Google 和 Facebook 等使用者身份提供者中的用户进行身份验证和授权。
主题
随后的两个组件构成了 Amazon Cognito。它们根据用户的访问需求独立或协同运行。
用户池
当您想要对您的应用程序或 API 进行身份验证和授权时,请创建用户池。用户池是一个用户目录,既有自助服务,也有管理员驱动的用户创建、管理和身份验证。用户池可以是独立的目录和 OIDC 身份提供者(IdP),也可以是员工身份和客户身份的第三方提供者的中间服务提供者(SP)。借助用户池,您可以在应用程序中为 SAML 2.0 和 OIDC IdP 中的组织员工身份提供单点登录(SSO)。还可以在应用程序中,为 Amazon、Google、Apple 和 Facebook 等 Auth 2.0 公共身份存储中组织的客户身份提供 SSO。有关客户身份和访问管理(CIAM)的更多信息,请参阅什么是 CIAM?
用户池不要求与身份池集成。从用户池中,您可以直接向应用程序、Web 服务器或 API 颁发经过身份验证的 JSON Web 令牌(JWT)。
身份池
当您想要授权经过身份验证的用户或匿名用户访问您的 Amazon 资源时,请设置 Amazon Cognito 身份池。身份池为您的应用程序颁发 Amazon 凭证,以便向用户提供资源。您可以使用可信身份提供者(如用户池或 SAML 2.0 服务)对用户进行身份验证。此身份提供者还可以选择为访客用户颁发凭证。身份池同时使用基于角色和基于属性的访问控制来管理您的用户访问 Amazon 资源的授权。
身份池不要求与用户池集成。身份池可以直接接受来自员工和使用者身份提供者的经过身份验证的声明。
将 Amazon Cognito 用户池和身份池一起使用
在本主题开头的图表中,您使用 Amazon Cognito 对用户进行身份验证,然后向他们授予对 Amazon Web Service 的访问权限。
-
应用程序用户通过用户池登录并接收 OAuth 2.0 令牌。
-
应用程序将用户池令牌及身份池交换为临时 Amazon 凭证,您可以将这些凭证用于 Amazon API 和 Amazon Command Line Interface(Amazon CLI)。
-
应用程序将凭证会话分配给用户,并提供对诸如 Amazon S3 和 Amazon DynamoDB 等 Amazon Web Services 的授权访问权限。
有关使用身份池和用户池的更多示例,请参阅常见的 Amazon Cognito 场景。
在 Amazon Cognito 中,责任共担模式
Amazon Cognito 的功能
用户池
Amazon Cognito 用户池是一个用户目录。利用用户池,您的用户可以通过 Amazon Cognito 登录您的 Web 或移动应用程序,也可以通过第三方 IdP 进行联合身份验证。联合用户和本地用户在您的用户池中拥有用户配置文件。
本地用户是那些已注册或您直接在用户池中创建的用户。您可以在 Amazon Web Services Management Console、Amazon SDK 或 Amazon Command Line Interface(Amazon CLI)中管理和自定义这些用户配置文件。
Amazon Cognito 用户池接受来自第三方 IdP 的令牌和断言,并将用户属性收集到它发布给应用程序的 JWT 中。您可以在一组 JWT 上对应用程序进行标准化,而 Amazon Cognito 则处理与 IdP 的互动,同时将其声明映射到中央令牌格式。
Amazon Cognito 用户池可以是独立的 IdP。Amazon Cognito 以 OpenID Connect(OIDC)标准为基础生成用于身份验证和授权的 JWT。当您登录本地用户时,用户池对这些用户具有权限。对本地用户进行身份验证时,您可以访问以下功能。
-
实现您自己的 Web 前端,此前端调用 Amazon Cognito 用户池 API 来对用户进行验证、授权和管理。
-
为用户设置多重身份验证(MFA)。Amazon Cognito 支持基于时间的一次性密码(TOTP)和短信 MFA。
-
可防止来自受恶意控制的用户账户的访问。
-
创建您自己的自定义多步骤身份验证流程。
-
在另一个目录中查找用户并将其迁移到 Amazon Cognito。
Amazon Cognito 用户池还可以扮演双重角色,即 IdP 的服务提供者(SP)和应用程序的 IdP。Amazon Cognito 用户池可以连接到如 Facebook 和 Google 等使用者 IdP,也可以连接到如 Okta 和 Active Directory Federation Services(ADFS)等员工 IdP。
有了 Amazon Cognito 用户池颁发的 OAuth 2.0 和 OpenID Connect(OIDC)令牌,您可以
-
在应用程序中接受 ID 令牌,该令牌可对用户进行身份验证,并提供设置用户配置文件所需的信息
-
在您的 API 中接受访问令牌,此令牌具有用于对用户的 API 调用进行授权的 OIDC 范围。
-
从 Amazon Cognito 身份池中检索 Amazon 凭证。
功能 | 描述 |
---|---|
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 Amazon 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 参考。
身份池
身份池是您分配给用户或访客并授权接收临时 Amazon 凭证的唯一标识符或身份的集合。当您以来自 SAML 2.0、OpenID Connect(OIDC)或 OAuth 2.0 社交身份提供者(IdP)的可信声明的形式向身份池提供身份验证证明时,您将用户与身份池中的身份相关联。身份池为身份创建的令牌可以从 Amazon Security Token Service(Amazon STS)检索临时会话凭证。
为了补充经过身份验证的身份,您还可以配置一个身份池来授权 Amazon 访问,而无需 IdP 身份验证。您可以提供自己的自定义身份验证证明,也可以不提供身份验证。您可以使用未经身份验证的身份向任何请求临时 Amazon 凭证的应用程序用户授予此类凭证。身份池还接受声明,并根据您自己的自定义模式,使用经过开发人员验证的身份颁发凭证。
使用 Amazon Cognito 身份池,您可以通过两种方式在您的 Amazon Web Services 账户中与 IAM policy 集成。您可以同时使用这两个功能,也可以单独使用。
基于角色的访问控制
当用户将声明传递到身份池时,Amazon Cognito 会选择它请求的 IAM 角色。要根据您的需求自定义角色的权限,您可以对每个角色应用 IAM policy。例如,如果您的用户证明自己在市场营销部门工作,则他们将获得相应角色的凭证,该角色的策略是根据营销部门访问需求量身定制的。Amazon Cognito 可以请求原定设置角色、基于查询用户声明的规则来请求角色,或者基于用户在用户池中的组成员资格来请求角色。您还可以配置角色信任策略,以便 IAM 仅信任您的身份池来生成临时会话。
访问控制属性
您的身份池读取用户声明中的属性,并将它们映射到用户临时会话中的主体标签。然后,您可以配置基于 IAM 资源的 IAM policy,以基于您的身份池中携带会话标签的 IAM 主体允许或拒绝访问资源。例如,如果您的用户证明自己在市场营销部门工作,则 Amazon 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 Amazon STS |
SAML 2.0 SP | Exchange SAML assertions for web identity credentials from Amazon STS |
OIDC SP | Exchange OIDC tokens for web identity credentials from Amazon STS |
OAuth 2.0 SP | Exchange OAuth tokens from Amazon, Facebook, Google, Apple, and Twitter for web identity credentials from Amazon STS |
Custom SP | With Amazon credentials, exchange claims in any format for web identity credentials from Amazon STS |
Unauthenticated access | Issue limited-access web identity credentials from Amazon 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 Amazon 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 Amazon STS for temporary Amazon 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 Amazon credentials based on claims from a SAML 2.0 IdP | ✓ | |
OIDC SP & credentials broker | Issue temporary Amazon credentials based on claims from an OIDC IdP | ✓ | |
OAuth 2.0 SP & credentials broker | Issue temporary Amazon credentials based on scopes from OAuth 2.0 social providers like Apple and Google | ✓ | |
Amazon Cognito user pool SP & credentials broker | Issue temporary Amazon credentials based on OIDC claims from an Amazon Cognito user pool | ✓ | |
Custom SP & credentials broker | Issue temporary Amazon 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 Amazon 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 | ✓ | |
Amazon WAF web ACLs | Monitor and control requests to your authentication environment with Amazon WAF | ✓ | |
Customize user attributes | Assign values to user attributes and add your own custom attributes | ✓ | |
Unauthenticated access | Issue limited-access web identity credentials from Amazon 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 Amazon STS temporary session, and use IAM policies to filter resource access based on principal tags | ✓ |
¹ 功能仅适用于本地用户。
Amazon Cognito 入门
有关首要任务和开始位置的指南,请参阅 Amazon Cognito 入门。
有关视频、文章、文档和示例应用程序,请参阅 Amazon Cognito 开发人员资源
您需要一个Amazon账户才能使用 Amazon Cognito。有关更多信息,请参阅 使用 Amazon Cognito 控制台。
区域可用性
Amazon Cognito 已在全球多个Amazon区域推出。在每个区域中,Amazon Cognito 分布在多个可用区内。这些可用区的物理位置是相互隔离的,但可通过私有、低延迟、高吞吐量和高度冗余的网络连接联合在一起。这些可用区使Amazon能够提供极高水平的可用性和冗余的服务(包括 Amazon Cognito),同时最大程度地减少延迟。
有关 Amazon Cognito 当前可用的所有区域的列表,请参阅《Amazon Web Services 一般参考》中的 Amazon 区域和端点。要详细了解每个区域中可用的可用区数量,请参阅 Amazon 全球基础设施
Amazon Cognito 的定价
有关 Amazon Cognito 定价的信息,请参阅 Amazon Cognito 定价