向用户池添加 OIDC 身份提供商
您可允许已具有 OpenID Connect (OIDC)

通过第三方(联合身份验证)进行登录可在 Amazon Cognito 用户池中实现。此功能不依赖于通过 Amazon Cognito 身份池(联合身份)实现的联合身份验证。
您可以在Amazon Web Services Management Console中、使用 Amazon CLI 或使用用户池 API 方法 CreateIdentityProvider 向用户池添加 OIDC IdP。
先决条件
在开始之前,您需要:
-
具有应用程序客户端和用户池域的用户池。有关更多信息,请参阅创建用户池。
-
具有以下配置的 OIDC IdP:
-
支持
client_secret_post
客户端身份验证。Amazon Cognito 不在 IdP 的 OIDC 发现端点上检查token_endpoint_auth_methods_supported
声明。Amazon Cognito 不支持client_secret_basic
客户端身份验证。有关客户端验证的更多信息,请参阅 OpenID Connect 文档中的客户端身份验证。 -
仅对 OIDC 端点使用 HTTPS,例如
openid_configuration
、userInfo
和jwks_uri
。 -
仅为 OIDC 端点使用 TCP 端口 80 和 443。
-
只能使用 HMAC-SHA 或 RSA 算法对 ID 令牌进行签名。
-
步骤 1:向 OIDC IdP 注册
在使用 Amazon Cognito 创建 OIDC IdP 之前,必须向 OIDC IdP 注册应用程序才能接收客户端 ID 和客户端密钥。
向 OIDC IdP 注册
-
使用 OIDC IdP 创建开发人员账户。
链接到 OIDC IdPOIDC IdP 如何安装 OIDC 发现 URL Salesforce https://login.salesforce.com
Ping Identity https://
您的 Ping 域地址
:9031/idp/userinfo.openid例如:
https://pf.company.com:9031/idp/userinfo.openid
Okta https://
您的 Okta 子域
.oktapreview.com或者
https://
Your Okta subdomain
.okta.comMicrosoft Azure Active Directory (Azure AD) https://login.microsoftonline.com/
{tenant}
/v2.0Google https://accounts.google.com
注意 Amazon Cognito 提供 Google 作为集成社交登录 IdP。建议使用集成 IdP。请参阅向用户池添加社交身份提供商。
-
向 OIDC IdP 注册具有
/oauth2/idpresponse
端点的用户池域 URL。这将确保 OIDC IdP 之后在对用户进行身份验证时通过 Amazon Cognito 接受此 URL。https://
<your-user-pool-domain>
/oauth2/idpresponse -
向 Amazon Cognito 用户池注册回调 URL。这是成功身份验证后 Amazon Cognito 将您的用户重定向到的页面的 URL。
https://
www.example.com
-
选择 scopes
(范围)。范围 openid 为必填字段。需要 email(电子邮件)范围来授予对 email 和 email_verified 声明 的访问权限。 -
OIDC IdP 为您提供客户端 ID 和客户端密钥。您在用户池中设置 OIDC IdP 时将使用它们。
示例:使用 Salesforce 作为用户池的 OIDC IdP
当您要在与 OIDC 兼容的 IdP(如 Salesforce)和您的用户池之间建立信任时,请使用 OIDC IdP。
-
在 Salesforce 开发人员网站上创建账户
。 -
请在 Salesforce 页面上,执行以下操作之一:
-
如果您使用的是 Lightning Experience,请选择设置齿轮图标,然后选择 Setup Home(设置主页)。
-
如果您使用的是 Salesforce Classic 并且在用户界面标题中看到 Setup(设置),请选择它。
-
如果您使用的是 Salesforce Classic 但没有在用户界面标题中看到 Setup(设置),请从顶部导航栏中选择您的姓名,然后从下拉列表中选择 Setup(设置)。
-
-
在左侧导航栏上,选择 Company Settings(公司设置)。
-
在导航栏上,选择 Domain(域),输入一个域,然后选择 Create(创建)。
-
在左侧导航栏上,选择在 Platform Tools(平台工具)下的 Apps(应用程序)。
-
选择 App Manager(应用程序管理器)。
-
-
选择 New connected app(新连接的应用程序)。
-
完成必填句段。
在 Start URL(启动 URL)下,在
/authorize
终端节点处输入使用您的 Salesforce IdP 登录的用户池域的 URL。当您的用户访问您连接的应用程序时,Salesforce 会将他们定向到此 URL 以完成登录。然后 Salesforce 将用户重定向到与应用程序客户端关联的回调 URL。https://
<your_user_pool_domain>
/authorize?response_type=code&client_id=<your_client_id>
&redirect_uri=https://www.example.com
&identity_provider=CorpSalesforce
-
启用 OAuth settings(OAuth 设置),然后在 Callback URL(回调 URL)中输入用户池域的
/oauth2/idpresponse
终端节点的 URL。这是 Salesforce 发出授权码的 URL,Amazon Cognito 会用该代码交换 OAuth 令牌。https://
<your_user_pool_domain>
/oauth2/idpresponse
-
-
选择 scopes
(范围)。您必须包含范围 openid。要授予对 email 和 email_verified 声明 的访问权限,请添加 email(电子邮件)范围。通过空格分隔范围。 -
选择 Create (创建) 。
在 Salesforce 中,客户端 ID 称为 Consumer Key(使用者密钥),客户端密钥为 Consumer Secret(使用者私有密钥)。记下您的客户端 ID 和客户端密钥。您将在下一节中使用它们。
步骤 2:将 OIDC IdP 添加到用户池
在本节中,配置用户池以通过 OIDC IdP 处理基于 OIDC 的身份验证请求。
添加 OIDC IdP(Amazon Cognito 控制台)
添加 OIDC IdP (Amazon CLI)
-
请参阅 CreateIdentityProvider API 方法的参数描述。
aws cognito-idp create-identity-provider --user-pool-id
string
--provider-namestring
--provider-type OIDC --provider-detailsmap
--attribute-mappingstring
--idp-identifiers (list) --cli-input-jsonstring
--generate-cli-skeletonstring
使用此提供商详细信息映射:
{ "client_id": "string", "client_secret": "string", "authorize_scopes": "string", "attributes_request_method": "string", "oidc_issuer": "string", "authorize_url": "string", "token_url": "string", "attributes_url": "string", "jwks_uri": "string" }
步骤 3:测试 OIDC IdP 配置
可以通过使用上两节中的元素并使用这些元素测试 OIDC IdP 配置来创建授权 URL。
https://
<your_user_pool_domain>
/oauth2/authorize?response_type=code&client_id=<your_client_id>
&redirect_uri=https://www.example.com
您可以在用户池 Domain name(域名)控制台页上找到您的域。您可以在 General settings(常规设置)页面上找到 client_id。对于 redirect_uri 参数,使用您的回调 URL。这是页面的 URL,在页面中,您的用户在身份验证成功后将被重定向。