【问题标题】:Trying to get more attributes using AWS Cognito's UserInfo endpoint, can't seem to make the UserInfo Claims param work尝试使用 AWS Cognito 的 UserInfo 端点获取更多属性,似乎无法使 UserInfo Claims 参数工作
【发布时间】:2020-08-14 10:15:29
【问题描述】:

我正在使用连接到我们客户的 Azure AD 身份提供商的 AWS Cognito 用户池。我能够通过调用 UserInfo 端点获取一些用户信息,但无法获取更多属性。我认为仅在 Cognito 中映射它们就足够了,但事实并非如此。显然,我必须使用“声明”参数在请求中指定我想要的 UserInfo 声明?我试着做这样的事情:

await axios({
    method: 'post',
    baseURL: Env.AWS_COGNITO_BASE_URL,
    url: '/oauth2/token',
    data: qs.stringify({
      grant_type: 'authorization_code',
      client_id: Env.AWS_COGNITO_CLIENT_ID,
      redirect_uri: this.redirectURI,
      code,
      claims: ['name', 'gender']
    }),
    headers: {'Content-Type': 'application/x-www-form-urlencoded'},
  })

关注these standard claims。但是,它没有返回我想要的属性。

我也尝试过这种格式,但也没有用:

claims: {
            userinfo: {
              name: {essential: true},
              nickname: {essential: true},
              gender: {essential: true},
              address: {essential: true},
            },
         },

那我该怎么做呢?我已经看到使用 SAML-tracer 返回的 SAML,它包含这些属性。

非常感谢您的帮助!

【问题讨论】:

    标签: oauth-2.0 azure-active-directory amazon-cognito openid openid-connect


    【解决方案1】:

    前面的答案是正确的,但我会扩展它,因为这让我永远理解。您只需要在/oath2/authorize? 范围内请求scope=openid,而不需要更多。

    现在可以这样设置-

    如果您设置这样的请求:

    https://{{user_pool_domain}}/oauth2/authorize?scope=aws.cognito.signin.user.admin+email+openid&client_id={{client_id}}&redirect_uri={{user_pool_domain}}

    然后使用该授权请求的访问令牌调用/oath2/userInfo/endpoint,您将无法返回所有属性。

    但是,如果您在授权调用中仅指定 scope=openid,然后在 /oath2/userInfo/ GET 请求中使用该访问令牌,则该访问令牌有权读取所有属性。所以你的初始调用应该是这样的:

    https://{{user_pool_domain}}/oauth2/authorize?scope=openid&client_id={{client_id}}&redirect_uri={{user_pool_domain}}

    【讨论】:

      【解决方案2】:

      在您调用授权端点时传入您想要的范围:

      https://{{user_pool_domain}}/oauth2/authorize?scope=openid

      【讨论】:

        猜你喜欢
        • 2020-11-25
        • 1970-01-01
        • 2020-01-19
        • 2015-10-09
        • 2015-04-22
        • 1970-01-01
        • 2021-09-05
        • 2018-05-09
        • 1970-01-01
        相关资源
        最近更新 更多