如何使用第三方 IdP 为我的 Amazon Cognito 用户池配置 IAM Identity Center?
3 分钟阅读
0
我想使用第三方身份提供者 (IdP) 为我的 Amazon Cognito 用户池配置 AWS IAM Identity Center。
解决方法
创建应用程序客户端和域名以创建 Amazon Cognito 用户池
注意:如果您的用户池具有应用程序客户端,请前往激活 IAM Identity Center 并添加用户部分。
完成以下步骤:
- 创建新应用程序。
- 创建格式为 https://cognitoexample.auth.region.amazoncognito.com 的 Amazon Cognito 前缀域。或者创建自定义域。有关详细信息,请参阅 Configuring a user pool domain(配置用户池域)。
- (可选)Apply branding to managed login pages(将品牌推广应用于管理的登录页面)。
激活 IAM Identity Center 并添加用户
注意:如果您已经有一个可用的 IAM Identity Center 环境,请转到配置 SAML 应用程序部分。
完成以下步骤:
- 查看 IAM Identity Center 先决条件和注意事项。
- 激活 IAM Identity Center。
**注意:**对于实例类型,您必须选择在AWS Organizations 管理账户中创建的 IAM Identity Center 组织实例。 - 确认您的身份来源,然后创建用户。
配置 SAML 应用程序
完成以下步骤:
- 打开 IAM Identity Center 控制台。
- 在导航窗格中,选择 Applications(应用程序)。
- 选择 Add application(添加应用程序),然后在 Setup preference(设置首选项)下选择 I have an application I want to set up(我有要设置的应用程序)。
- 对于 Application type(应用程序类型),选择 SAML 2.0,然后选择 Next(下一步)。
- 在 Configure application(配置应用程序)页面上,输入显示名称和描述。
- 记下 IAM Identity Center SAML 元数据文件的 URL 或选择 Download(下载)超链接以下载文件。
- 在 Application metadata(应用程序元数据)下,选择 Manually type your metadata values(手动键入您的元数据值)。然后,输入以下值:
对于 Application Assertion Consumer Service (ACS) URL(应用程序断言消费者服务 (ACS) URL),请输入 https://domain-prefix.auth.region.amazoncognito.com/saml2/idpresponse。
对于 Application SAML audience(应用程序 SAML 受众),输入 urn:amazon:cognito:sp:userpool-id。
**注意:**将 domain-prefix 替换为您的域前缀,将 region 替换为您的 AWS 区域,将 userpool-id 替换为您的用户池 ID。 - 选择 Submit(提交)。
- 在应用程序的 Details(详细信息)页面上,选择 Actions(操作)下拉列表。
- 选择 Edit attribute mappings(编辑属性映射),然后输入以下属性:
对于 User attribute in the application(应用程序中的用户属性),保留默认的 subject。
对于 Maps to this string value or user attribute in IAM Identity Center(映射到 IAM Identity Center 中的此字符串值或用户属性),输入 ${user:subject}。
对于 Format(格式),输入 Persistent(永久)。
对于 User attribute in the application(应用程序中的用户属性),输入 email(电子邮件)。
对于 Maps to this string value or user attribute in IAM Identity Center(映射到 IAM Identity Center 中的此字符串值或用户属性),输入 ${user:email}。
对于 Format(格式),输入 Basic(基本)。
**注意:**当您登录时,IAM Identity Center 会将属性映射发送到 Amazon Cognito。确保映射所有用户池的必需属性。有关可用映射属性的详细信息,请参阅支持的外部身份提供者属性。 - 选择 Submit(提交)。
- 在 Assigned users and groups(分配的用户和组)部分下,选择 Assign users and groups(分配用户和组)。
- 找到您的用户,然后选择 Assign(分配)。
在您的用户池中将 IAM Identity Center 配置为 SAML IdP
要在用户池中配置 SAML IdP,请参阅在用户池中添加和管理 SAML 身份提供者。当您指定 SAML 提供者属性映射时,请在 SAML attribute(SAML 属性)字段中输入有效的电子邮件。对于 User pool attribute(用户池属性),选择 email(电子邮件)。
有关提供者名称和标识符的信息,请参阅 SAML 身份提供者名称和标识符。
使用用户池应用程序客户端集成身份提供者
完成以下步骤:
- 打开 Amazon Cognito 控制台。
- 在导航窗格中,选择 User pools(用户池)。
- 在 Applications(应用程序)下,选择 App clients(应用程序客户端)。
- 选择应用程序客户端。
- 在 Login pages(登录页面)部分中,选择 Edit(编辑)。
- 在 Identity providers(身份提供者)部分中,选择您的 IdP。
- 选择 Save changes(保存更改)。
测试设置
要测试服务提供商 (SP) 发起的登录,请完成以下步骤:
- 打开 Amazon Cognito 控制台,然后在应用程序客户端的 Login pages(登录页面)选项卡中选择 View login page(查看登录页面)。或者,创建登录端点 URL。使用以下示例命名模式,并将示例值替换为您的值:
https://my-user-pool.auth.us-east-1.amazoncognito.com/login?response_type=code&client_id=a1b2c3d4e5f6g7h8i9j0k1l2m3&redirect_uri=https://example.com
对于 OAuth 2.0 grant types(OAuth 2.0 授权类型),选择 Implicit grant(隐式授权)。然后在请求 URL 中将 response_type 设置为 token。 - 在 Login pages(登录页面)选项卡中,选择 IAM Identity Center IdP。
如果您的浏览器将您重定向到应用程序客户端的回调 URL,则您成功以用户身份登录。用户池令牌会直接显示在 Web 浏览器地址栏的 URL 中。
注意:要跳过此步骤,请使用以下命名模式创建授权端点 URL:
https://yourDomainPrefix.auth.region.amazoncognito.com/oauth2/authorize?response_type=token&identity_provider=samlProviderName&client_id=yourClientId&redirect_uri=redirectUrl&scope=allowedOauthScopes - 输入用户凭证并选择 Login(登录)。
当 Amazon Cognito 使用代码或令牌将您重定向到回调 URL 时,设置即告完成。
要测试身份提供者 (IdP) 发起的登录,请完成以下步骤:
- 打开 Amazon Cognito 控制台。
- 在导航窗格中,选择 User pools(用户池),然后选择您的用户池。
- 在导航窗格中,选择 Social and external provider(社交和外部提供商)。
- 选择您的 IdP,然后在 Identity provider information(身份提供者信息)部分中选择 Edit(编辑)。
- 在 IdP-initiated SAML sign-in(IdP 发起的 SAML 登录)部分中,选择 Accept SP-initiated and IdP-initiated SAML assertions(接受 SP 发起和 IdP 发起的 SAML 断言)。
**注意:**您可以将其他 SAML 提供商添加到接受采用 IdP 发起登录的 SAML 提供商的应用程序客户端。从应用程序客户端中移除其他社交或 OpenID Connect (OIDC) 提供商或 Cognito 用户池目录。 - 选择 Save changes(保存更改)。
- 打开 IAM Identity Center 控制台,然后选择您的 SAML 2.0 应用程序。
- 选择 Actions(操作)下拉列表,然后选择 Edit configuration(编辑配置)。
- 在 Application properties(应用程序属性)下,添加以下中继状态值:
identity_provider=identity-provider-name&client_id=app-client-id&redirect_uri=callback-url&response_type=token&scope=openid+email
**注意:**请将示例值替换为您的值。 - 选择 Submit(提交)。
- 在导航窗格中,选择 Settings(设置)。
- 在 Identity source(身份来源)部分中,复制 AWS 访问门户 URL,然后在浏览器中将其打开。
- 输入用户凭证并选择 Login(登录)。
- 选择 Cognito 应用程序。
如果 Amazon Cognito 使用代码或令牌将您重定向到回调 URL,则说明设置已完成。
相关信息
How federated sign-in works in Amazon Cognito user pools(联合登录在 Amazon Cognito 用户池中的运作方式)
Understanding user pool JSON web tokens (JWTs)(了解用户池 JSON Web 令牌 (JWT))
- 语言
- 中文 (简体)

AWS 官方已更新 4 个月前
没有评论
