UserInfo 端点 - Amazon Cognito

本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。

UserInfo 端点

userInfo端点是一个 OpenID Connect (OIDC) userInfo 端点。当服务提供商出示您的 令牌端点 颁发的访问令牌时,它会使用用户属性进行响应。用户访问令牌中的作用域定义了 userInfo 终端节点在其响应中返回的用户属性。openid 范围必须是访问令牌声明的范围之一。

Amazon Cognito 会根据用户池API请求发布访问令牌,例如。InitiateAuth由于它们不包含任何范围,因此 userInfo 端点不接受这些访问令牌。而是必须由您出示来自令牌端点的访问令牌。

您的 OAuth 2.0 第三方身份提供商 (IdP) 还托管终端节点。userInfo当您的用户使用该 IdP 进行身份验证时,Amazon Cognito 会以静默方式与 IdP 终端节点交换授权码。token您的用户池传递 IdP 访问令牌以授权从 IdP 端点检索用户信息。userInfo

GET/oauth2/ userInfo

您的应用程序直接对此端点发出请求,而不通过浏览器。

有关更多信息,请参阅 OpenID Connect (OIDC) 规范中的UserInfo端点

标头中的请求参数

Authorization: Bearer <access_token>

在授权标头字段中传递访问令牌。

必需。

示例-请求

GET /oauth2/userInfo HTTP/1.1 Content-Type: application/x-amz-json-1.1 Authorization: Bearer eyJra12345EXAMPLE User-Agent: [User agent] Accept: */* Host: auth.example.com Accept-Encoding: gzip, deflate, br Connection: keep-alive

示例 — 正面回应

HTTP/1.1 200 OK Content-Type: application/json;charset=UTF-8 Content-Length: [Integer] Date: [Timestamp] x-amz-cognito-request-id: [UUID] X-Content-Type-Options: nosniff X-XSS-Protection: 1; mode=block Cache-Control: no-cache, no-store, max-age=0, must-revalidate Pragma: no-cache Expires: 0 Strict-Transport-Security: max-age=31536000 ; includeSubDomains X-Frame-Options: DENY Server: Server Connection: keep-alive { "sub": "[UUID]", "email_verified": "true", "custom:mycustom1": "CustomValue", "phone_number_verified": "true", "phone_number": "+12065551212", "email": "bob@example.com", "username": "bob" }

有关OIDC索赔列表,请参阅标准索赔。目前,Amazon Cognito 将 email_verifiedphone_number_verified 的值返回为字符串。

负面回应示例

示例-错误的请求

HTTP/1.1 400 Bad Request WWW-Authenticate: error="invalid_request", error_description="Bad OAuth2 request at UserInfo Endpoint"
invalid_request

请求缺少必填参数,包含不支持的参数值,或者格式不正确。

示例-不良代币

HTTP/1.1 401 Unauthorized WWW-Authenticate: error="invalid_token", error_description="Access token is expired, disabled, or deleted, or the user has globally signed out."
invalid_token

访问令牌已过期、已撤销、格式错误或无效。