gpt4 book ai didi

aws-cloudformation - 应用同步 : Get user information in $context when using AWS_IAM auth

转载 作者:行者123 更新时间:2023-12-04 02:04:20 33 4
gpt4 key购买 nike

在 AppSync 中,当您使用 Cognito 用户池作为您的身份验证设置时,您将获得

identity: 
{ sub: 'bcb5cd53-315a-40df-a41b-1db02a4c1bd9',
issuer: 'https://cognito-idp.us-west-2.amazonaws.com/us-west-2_oicu812',
username: 'skillet',
claims:
{ sub: 'bcb5cd53-315a-40df-a41b-1db02a4c1bd9',
aud: '7re1oap5fhm3ngpje9r81vgpoe',
email_verified: true,
event_id: 'bb65ba5d-4689-11e8-bee7-2d0da8da81ab',
token_use: 'id',
auth_time: 1524441800,
iss: 'https://cognito-idp.us-west-2.amazonaws.com/us-west-2_oicu812',
'cognito:username': 'skillet',
exp: 1524459387,
iat: 1524455787,
email: '<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="6d001408000c04012d03021d08430e0200" rel="noreferrer noopener nofollow">[email protected]</a>' },
sourceIp: [ '11.222.33.200' ],
defaultAuthStrategy: 'ALLOW',
groups: null }

但是,当您使用 AWS_IAM 身份验证时,您会得到

identity:
{ accountId: '12121212121', //<--- my amazon account ID
cognitoIdentityPoolId: 'us-west-2:39b1f3e4-330e-40f6-b738-266682302b59',
cognitoIdentityId: 'us-west-2:a458498b-b1ac-46c1-9c5e-bf932bad0d95',
sourceIp: [ '33.222.11.200' ],
username: 'AROAJGBZT5A433EVW6O3Q:CognitoIdentityCredentials',
userArn: 'arn:aws:sts::454227793445:assumed-role/MEMORYCARDS-CognitoAuthorizedRole-dev/CognitoIdentityCredentials',
cognitoIdentityAuthType: 'authenticated',
cognitoIdentityAuthProvider: '"cognito-idp.us-west-2.amazonaws.com/us-west-2_HighBob","cognito-idp.us-west-2.amazonaws.com/us-west-2_HighBob:CognitoSignIn:1a072f08-5c61-4c89-807e-417d22702eb7"' }

文档说这是预期的,https://docs.aws.amazon.com/appsync/latest/devguide/resolver-context-reference.html 。但是,如果您使用连接到 Cognito 的 AWS_IAM (需要进行未经身份验证的访问),您应该如何获取用户的用户名、电子邮件、子地址等?使用 AWS_IAM 类型身份验证时,我需要访问用户的声明。

最佳答案

为了使用户的用户名、电子邮件、子地址等可通过 AppSync API 访问,有一个答案:https://stackoverflow.com/a/42405528/1207523

总而言之,您希望将用户池 ID token 发送到您的 API(例如 AppSync 或 API Gateway)。您的 API 请求已通过 IAM 身份验证。然后,您在 Lambda 函数中验证 ID token ,现在您就拥有了经过验证的 IAM 用户和用户池数据。

您希望使用 IAM 的 identity.cognitoIdentityId 作为用户表的主键。添加 ID token 中包含的数据(用户名、电子邮件等)作为属性。

这样您就可以通过 API 提供用户的声明。例如,现在您可以将 $ctx.identity.cognitoIdentityId 设置为项目的所有者。然后其他用户也许可以通过 GraphQL 解析器看到所有者的名称。

如果您需要在解析器中访问用户的声明,恐怕目前似乎不可能。我对此提出了一个问题,因为这对授权非常有帮助:Group authorization in AppSync using IAM authentication

在这种情况下,您可以使用 Lambda 作为数据源并从上述用户表中检索用户的声明,而不是使用解析器。

现在有点困难:)

关于aws-cloudformation - 应用同步 : Get user information in $context when using AWS_IAM auth,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50085654/

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