自定义属性未传递到AWS Cognito创建的ID_TOKEN

问题描述 投票:0回答:1

用户登录成功后,我无法在AWS Cognito返回的ID_TOKEN中获取自定义属性。

我试过的步骤:

1.Created用户池2.Created应用程序客户端并检查自定义属性(customattrib1,customattrib2)

用户池屏幕:

enter image description here

在app client config中检查自定义属性

enter image description here

3.Created用户使用admin-create-user api

下图显示了用户属性的值:

enter image description here

4.在客户端app中使用aws-cognito-auth.js在用户中签名。返回的ID令牌不包含自定义属性。

ID_TOKEN

{
  "at_hash": "PKfjYDaiEty5mUOyJZlPQA",
  "sub": "639d5016-2bd3-4c6f-b82d-21ae38071b09",
  "email_verified": true,
  "iss": "https://cognito-idp.ap-south-1.amazonaws.com/ap-south-1_XXXXXXX",
  "phone_number_verified": true,
  "cognito:username": "testuser",
  "aud": "XYXYXYXYX",
  "token_use": "id",
  "auth_time": 1549349674,
  "phone_number": "##########",
  "exp": 1549353274,
  "iat": 1549349674,
  "email": "[email protected]"
}

我已经检查了下面的链接,其中有关于此问题的一些信息,但到目前为止没有任何帮助。

Adding Cognito custom attributes post pool creation?

Cognito User Pool custom attributes do not show up in the ID token if user pool is configured with a SAML identity provider

Cognito User Pool custom attributes do not show up in the ID token if user pool is configured with a SAML identity provider

https://www.reddit.com/r/aws/comments/a07dwg/cognito_add_custom_attribute_to_jwt_token/

请帮我弄清楚我是否遗漏了什么......

amazon-web-services aws-sdk amazon-cognito oidc aws-userpools
1个回答
4
投票

我遇到了同样的麻烦,当我在寻找解决方案时,你的问题出现了。

当我在“应用客户端设置”中启用配置文件范围时,我的自定义属性开始出现在ID令牌中。 (可从以下位置获取:AWS控制台 - >'用户池' - >单击您的池 - >'应用客户端设置' - >'允许的OAuth范围')

(顺便说一句:我被documentation的这句话误导了:“openid范围返回ID令牌中客户端可读的所有用户属性”。在我的情况下,openid范围是不够的。)


2
投票
  • 在Cognito用户池中,转到常规设置 - >应用程序客户端,然后为每个应用程序客户端单击Show Details,然后单击Set attribute read and write permissions。选中Readable Attributes下属性名称旁边的复选框。
  • 在Cognito用户池中,转到App客户端设置 - >允许的OAuth范围并启用profile范围。
© www.soinside.com 2019 - 2024. All rights reserved.