# 有人有可用的 AWS Cognito 配置（支持 OAuth2、OpenID 或 SSO）吗？

**URL:** https://meta.discourse.org/t/anyone-have-a-working-aws-cognito-configuration-w-ouath2-openid-or-sso/123579
**Category:** SSO
**Tags:** openid-connect
**Created:** [2019 年7 月 21 日 15:27 UTC](https://meta.discourse.org/t/anyone-have-a-working-aws-cognito-configuration-w-ouath2-openid-or-sso/123579 "2019-07-21T15:27:55Z")
**Posts on this page:** 1
**Showing post:** 4

<div class="post-metadata">

### Author: ![weallwegot](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/weallwegot/32/124753_2.png) [@weallwegot](https://meta.discourse.org/u/weallwegot)
#### Post date: [2021 年4 月 27 日 04:40 UTC](https://meta.discourse.org/t/anyone-have-a-working-aws-cognito-configuration-w-ouath2-openid-or-sso/123579/4 "2021-04-27T04:40:13Z")

</div>

将 AWS Cognito 作为 [OpenID Connect 插件](https://meta.discourse.org/t/openid-connect-authentication-plugin/103632) 的身份提供商：

1. 在 AWS Cognito 网页控制台中，点击“创建用户池”（Create a User Pool）按钮。
2. 点击“查看默认设置”（Review Defaults）以使用大部分默认配置。  
2a. 在创建用户池之前，请务必点击“添加应用客户端”（Add an App Client）。  
2b. 创建一个应用客户端；为其命名，并取消勾选除 `Enable refresh token based authentication (ALLOW_REFRESH_TOKEN_AUTH)` 之外的所有选项。

 ![Screen Shot 2021-04-26 at 11.31.59 PM](https://global.discourse-cdn.com/meta/original/3X/7/0/708649f411b8caf628e186f4d846de256e651b40.png)

1. 点击“创建用户池”（Create pool）。

2. 现在，在左侧菜单的“常规设置”（General Settings）下，点击“应用客户端”（App Client），并记录 **`App client id`** 和 **`App client secret`** 的值。

3. 接下来，在左侧菜单的“应用集成”（App integration）下，点击“域名”（Domain name）。在此处输入一个子域名。此处的名称将作为用户登录时被路由到的域名。  

4. 在 AWS Cognito 控制台的左上角，点击“联合身份”（Federated Identities），该选项稍难查找。  
 ![federated-identities](https://global.discourse-cdn.com/meta/original/3X/3/b/3bd36561091608918bbfaf7831d355f2b37c0ad8.png)

5. 进入后，点击 `Create new identity pool`（创建新身份池）。

6. 为身份池命名。  
8b. 在 `Authentication providers`（身份验证提供商）部分，使用之前创建的用户池的 User Pool ID 以及之前创建的应用客户端的 App client id。

 ![Screen Shot 2021-04-27 at 12.04.19 AM](https://global.discourse-cdn.com/meta/original/3X/b/6/b67d4f62a875b60c0e74abb07ac4fb2fafe783ff.png)

1. 点击“创建池”（Create Pool），并允许控制台创建与新身份池配合使用的 IAM 角色。
2. 至此，您已具备所有必要信息，可以开始配置 Discourse 实例的正确站点设置了（假设您已安装该插件）。

**openid connect enabled** ：启用此项。  
**openid connect client id** ：使用前面步骤中获取的 `App Client Id`。  
**openid connect client secret** ：使用前面步骤中看到的 `App Client Secret`。  
**openid connect discovery document** ：发现文档 URL 的链接格式如下。您可以在步骤 8b 的截图中看到 `userPoolId` 的格式示例：

```plaintext
https://cognito-idp.{region}.amazonaws.com/{userPoolId}/.well-known/openid-configuration

```

要检查 URL 格式是否正确，只需将其粘贴到浏览器中，您应该能收到一个包含授权端点、颁发者（issuer）及其他信息的 JSON 响应。

**openid connect authorize scope** ：`openid email`

* * *

**其他可能有用的内容**

- [Stackoverflow：关于发现文档 URL 格式的背景信息](https://stackoverflow.com/questions/47664727/can-i-use-aws-cognito-to-provide-a-open-id-connect-endpoint)
- [Stackoverflow：如果在检查发现文档 URL 时遇到正则表达式匹配错误，请检查是否在发现文档 URL 中使用了错误的格式而非用户池 ID。](https://stackoverflow.com/questions/37223695/aws-cognito-error-identitypoolid-failed-to-satisfy-constraint)
- [Stackoverflow：请务必设置域名，否则会出现此问题](https://stackoverflow.com/questions/50569395/aws-cognito-user-pools-and-openid)

---

_[View the full topic](https://meta.discourse.org/t/anyone-have-a-working-aws-cognito-configuration-w-ouath2-openid-or-sso/123579)._
