gpt4 book ai didi

amazon-web-services - AWS Cognito - 凭证问题

转载 作者:行者123 更新时间:2023-12-01 01:46:51 24 4
gpt4 key购买 nike

我正在尝试使用 AWS Cognito 进行身份验证(使用 Google)并授权用户,目的是为授权用户分配 IAM 角色。

到目前为止,我已按照以下步骤操作

  • 使用授权端点启动 Google OAuth 进程
    http://docs.aws.amazon.com/cognito/latest/developerguide/authorization-endpoint.html

    I am using "Grant flow" I receive a such as code=b3e8bca6-5a01-45db-b4c6-cd6900d0xxxx

  • 向誓言/ token 发帖请求 http://docs.aws.amazon.com/cognito/latest/developerguide/token-endpoint.html

    I receive the following information:


    "id_token": "eyJraWQiOiJJR2NVdHJcL3pOa3pQK1lre...........",
    "access_token": "eyJraWQiOiJCbWx0cjJvMnJlVGhHW..........",
    "refresh_token": "eyJjdHkiOiJKV1QiLCJlbmMiOi............",
    "expires_in": 3600,
    "token_type": "Bearer"
  • 尝试使用 CognitoIdentityCredentials 获取 AWS 凭证
    AWS.config.credentials = new AWS.CognitoIdentityCredentials({
    IdentityPoolId: environment.identityPoolId, // Federated ID eu-west-2:af47703f-350c-4018-ae6a-xxxxxx
    RoleArn: environment.roleArn,// IAM role
    Logins: { 'accounts.google.com': data.id_token },
    });

    AWS.config.getCredentials((error) => {
    if(error) console.log("Error: ", error);
    this.creds = AWS.config.credentials;
    });

  • I get a bad request 500 error


    {"__type":"NotAuthorizedException","message":"Invalid login token. Issuer doesn't match providerName"}

    几个问题
  • 遵循的步骤顺序是否正确?
  • 如何获得 CongnitoUserId ? id_token是一个很长的字符串,但不确定我可以从中提取哪些信息?
  • 最后如何获得 accessKey 进行 AWS 调用?

  • 任何帮助或方向将不胜感激。

    谢谢

    最佳答案

    Is the sequence of steps followed correct?



    我相信是这样。

    id_token is a very long string, but not sure what information can I extract from it?



    两者 id_tokenaccess_tokenJWT s。您可以对点之间的字符串进行 base64 解码以提取 token 的内容。通常我们关心中间部分或有效载荷。

    您可以将这些 token 粘贴到解码器中,例如 this one ,并在浏览器中查看内容。在 JavaScript 中, atob() 正如你所期望的那样工作。

    我不确定您要使用哪个用户 ID,但如果用户名足够,则 id_token 包含 cognito:username key 。

    Finally how to I get accessKey to make AWS calls?



    更改您的 Logins 中的提供商 map 。

    如果您直接与 Google 交谈,而不是通过 Cognito(通过 /oauth2/authorize)与 Google 交谈,您将使用 accounts.google.comLogins map 如您的示例所示。

    但是,您取回的 token 来自 Cognito,而不是来自 Google。两个 token 都包含 iss (issuer) 键,它(很可能)是您的用户池 ID。这是您应该在 Logins 中使用的值 map 。假设发行者是您的用户池:
    Logins: {
    'cognito-idp.us-east-1.amazonaws.com/us-east-1_xxxxxxxx': token
    }

    关于amazon-web-services - AWS Cognito - 凭证问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47998439/

    24 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com