缺少用于联合Google用户的UserAttributes

发布于 2025-01-18 08:48:11 字数 2450 浏览 4 评论 0原文

我正在尝试将Google作为IDP集成到我们现有的Cognito UserPool中。到目前为止,一切都设置了,我可以使用Google进行注册/签名,该Google创建新用户。我正在使用Presignup lambda触发器来链接现有用户,或者如果没有现有的用户,则创建新的本地用户。现在,我期望event.request.userattributes ['name']包含Google提供的用户名称,或者至少在id_token中看到属性。但是我认为目前没有可能获得这些价值观。我们开始使用Cognito作为用户名/密码的商店,并且没有用UserAttributes填写或按需要标记。

我已经使用以下范围设置了Google集成:

  • .../auth/userInfo.email
  • .../auth/auth/userInfo.profile.profile
  • openID

在UserPoolClient i:

  • 标记名称作为可读取和可写的属性(以及其他属性)
  • 检查以下允许的oauth scopes email> emailOpenID配置文件。这些也是OAuth流的负责的Web客户端中定义的。

在联邦部分中,我配置了属性映射:

,我将name属性映射到用于测试内容的自定义属性。但是,这或映射name to name都没有工作。

有效负载我在此事件中得到:

{{PreSignUp_ExternalProvider .... Google_11...} {map[cognito:email_alias: cognito:phone_number_alias: email:[email protected] email_verified:true] map[] map[]} {false false false}}

id_token content:

{
  "at_hash": "..",
  "sub": "52...",
  "email_verified": true,
  "iss": "https://cognito-idp.us-west-2.amazonaws.com/...",
  "cognito:username": "52..",
  "origin_jti": "..",
  "aud": "...",
  "identities": [
    {
      "userId": "11...",
      "providerName": "Google",
      "providerType": "Google",
      "issuer": null,
      "primary": "false",
      "dateCreated": "1648828708886"
    }
  ],
  "token_use": "id",
  "auth_time": 1648828717,
  "exp": 1648830828,
  "iat": 1648830228,
  "jti": "...",
  "email": "[email protected]"
}

access_token content:content:

{
  "origin_jti": "02...",
  "sub": "52...",
  "token_use": "access",
  "scope": "openid profile",
  "auth_time": 1648828717,
  "iss": "https://cognito-idp.us-west-2.amazonaws.com/....",
  "exp": 1648829317,
  "iat": 1648828717,
  "version": 2,
  "jti": "..",
  "client_id": "...",
  "username": "52..."
}

I'm trying to integrate Google as an IdP in our existing Cognito UserPool. Everything is set up so far, and I can SignUp/SignIn using Google, which creates the new user. I'm using the PreSignUp Lambda trigger to Link an existing user or create a new native one if there's no existing one. Now I was expecting that the event.Request.UserAttributes['name'] contains the user's name as provided by Google or at least seeing the attribute in the id_token. But I see no possibility to get those values at the moment. We started using Cognito just as the store for username/password, and none of the userAttributes are filled nor marked as required.

I have set up the Google integration with the following scopes:

  • .../auth/userinfo.email
  • .../auth/userinfo.profile
  • openid

In the UserPoolClient I:

  • marked name as read- and writeable attribute (along with others)
  • Checked the following allowed OAuth scopes email, openid, and profile. Those are also defined in the Web-Client in charge of the OAuth flow.

In the Federation section, I configured the attribute mapping:
Attribute mapping for Google in Cognito

Testwise, I mapped the name attribute to a custom attribute I used to test stuff. But neither this nor the mapping name to name worked.

Payload I get in the event:

{{PreSignUp_ExternalProvider .... Google_11...} {map[cognito:email_alias: cognito:phone_number_alias: email:[email protected] email_verified:true] map[] map[]} {false false false}}

id_token content:

{
  "at_hash": "..",
  "sub": "52...",
  "email_verified": true,
  "iss": "https://cognito-idp.us-west-2.amazonaws.com/...",
  "cognito:username": "52..",
  "origin_jti": "..",
  "aud": "...",
  "identities": [
    {
      "userId": "11...",
      "providerName": "Google",
      "providerType": "Google",
      "issuer": null,
      "primary": "false",
      "dateCreated": "1648828708886"
    }
  ],
  "token_use": "id",
  "auth_time": 1648828717,
  "exp": 1648830828,
  "iat": 1648830228,
  "jti": "...",
  "email": "[email protected]"
}

access_token content:

{
  "origin_jti": "02...",
  "sub": "52...",
  "token_use": "access",
  "scope": "openid profile",
  "auth_time": 1648828717,
  "iss": "https://cognito-idp.us-west-2.amazonaws.com/....",
  "exp": 1648829317,
  "iat": 1648828717,
  "version": 2,
  "jti": "..",
  "client_id": "...",
  "username": "52..."
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

小矜持 2025-01-25 08:48:11

现在它正在工作,即使我无法说明错误。我再次重新创建了整个测试集,并确保了以下值的正确值:

  • 属性映射
  • 授权范围
  • OAuth示波器
  • 允许前端选择的

示波器,我添加了scopes email> email> email openID可以肯定,现在我在预注册触发lambda和id-token中获得name属性。

Now it's working, even though I cannot state the error. I recreated the whole test set again and ensured the correct values of the following:

  • attribute mappings
  • authorized scopes
  • Allowed OAuth scopes
  • Scopes selected by the frontend

I added the scopes email, profile, and openid to be sure, and now I get the name attribute within the pre signup trigger lambda and in the ID-Token.

探春 2025-01-25 08:48:11

当使用Cognito作为REST API网关设置作为Lambda代理时,我也遇到了同样的问题。就我而言,声称lambda收到的没有包含与Google签署的用户的所有用户属性。

最后,我确定问题是从Cognito获取ID令牌的前端配置。我正在使用Amplify auth,并且缺少OAuth配置中的'配置文件>范围。

Amplify.configure({
    Auth: {
        ...
        oauth: {
            ...
            scope: ['phone', 'email', 'profile', 'openid', 'aws.cognito.signin.user.admin'],
            ...
        }
    }
});

I had the same problem when using cognito as an authorizer for a REST API Gateway setup as a lambda proxy. In my case, the claims that the lambda received did not include all the user's attributes for a user signed in with Google.

Finally I identified that the issue was in the front-end configuration for getting the id tokens from cognito. I was using Amplify Auth and was missing the 'profile' scope in the oauth configuration.

Amplify.configure({
    Auth: {
        ...
        oauth: {
            ...
            scope: ['phone', 'email', 'profile', 'openid', 'aws.cognito.signin.user.admin'],
            ...
        }
    }
});
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文