gpt4 book ai didi

amazon-cognito - AWS Cognito 外部用户池身份提供商 (OIDC)

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

我正在使用与外部提供商 (Twitch) 集成的 Cognito App Client用户身份验证工作正常,但由于来自 auth 服务器的代码被 Cognito 使用,我不确定我应该如何发送带有 token 的 Twitch 请求,我通常会从 twitch 获得我 Cognito 不会使用此代码。我只有 Cognito 代码,我可以在 https://{my-domain}/oauth2/token 请求中使用它来换取 Cognito token 。请求返回 id_token、access_token 和 refresh_token,解码后的样子身份证

{
"at_hash": "yTNkeTAqzqcXCYi3yLL2Pw",
"sub": "3cfba641-4058-475f-9818-17291175fd31",
"cognito:groups": [
"us-east-1_xxxxxxxxxxxx"
],
"iss": "https://cognito-idp.us-east-1.amazonaws.com/us-east-1_xxxxxxxxxxxx",
"cognito:username": "xxxxxxxxxxxx",
"preferred_username": "xxxxxxxxxxxx",
"nonce": "SxxlipCDVbXbcXa1H7Uf9_nM0uOurAAObUVCyreBDDux99QoAngUoiGdE0me-0Zon6fEVLLTSqD4EN1Y6_lFm48MaoBaxyywZCQKOT70gfQEfkuhlsjImJd1ko3qH3QKdlmvWSPCUZoACPYNSgR364VPELyQTVMkRTCt9eYROag",
"aud": "35l1cn53cnj9sv1ndu8u01amk0",
"identities": [
{
"userId": "xxxxxxxxxxxx",
"providerName": "xxxxxxxxxxxx",
"providerType": "OIDC",
"issuer": null,
"primary": "true",
"dateCreated": "1588191000072"
}
],
"token_use": "id",
"auth_time": 1588191003,
"exp": 1588194603,
"iat": 1588191003
}

访问 token

{
"sub": "3cfba641-4058-475f-9818-17291175fd31",
"cognito:groups": [
"us-east-1_xxxxxxxxxxxx"
],
"token_use": "access",
"scope": "aws.cognito.signin.user.admin phone openid profile email",
"auth_time": 1588191003,
"iss": "https://cognito-idp.us-east-1.amazonaws.com/us-east-1_xxxxxxxxxxxx",
"exp": 1588194603,
"iat": 1588191003,
"version": 2,
"jti": "55863213-c764-4b07-a386-a9c93d14e4b2",
"client_id": "xxxxxxxxxxxx",
"username": "xxxxxxxxxxxx"
}

如何获取用户 token 以调用 Twitch API(例如 GET https://api.twitch.tv/helix/users 具有授权用户 token 的端点)

最佳答案

注意 - 如果操作不当,您会将敏感属性暴露给客户端。

您需要创建 2 个版本的属性 - customdev:custom,将 oidc 提供程序属性映射到 custom 属性(看起来像 dev:custom 不可映射),然后在 TokenGeneration_HostedAuth 触发器中,您需要获取这些 custom 属性,设置 dev:custom 的,然后删除 custom

似乎是一种调整,但我看不到另一种方法可以做到这一点并确保 token 安全。

解决方案是在您的用户池中创建自定义属性,然后为身份提供商映射这些属性。看起来像:

'custom:refresh_token': refresh_token
'custom:id_token': id_token
'custom:access_token': access_token

Cloudformation 模板:

用户池

....
Schema: [
{
AttributeDataType: 'String',
DeveloperOnlyAttribute: true,
Mutable: true,
Name: 'refresh_token',
Required: false,
},
{
AttributeDataType: 'String',
DeveloperOnlyAttribute: true,
Mutable: true,
Name: 'access_token',
Required: false,
},
{
AttributeDataType: 'String',
DeveloperOnlyAttribute: true,
Mutable: true,
Name: 'id_token',
Required: false,
},
{
AttributeDataType: 'String',
Mutable: true,
Name: 'refresh_token',
Required: false,
},
{
AttributeDataType: 'String',
Mutable: true,
Name: 'access_token',
Required: false,
},
{
AttributeDataType: 'String',
Mutable: true,
Name: 'id_token',
Required: false,
},
],
....

用户池身份提供者

....
AttributeMapping: {
'custom:refresh_token': 'refresh_token',
'custom:access_token': 'access_token',
'custom:id_token': 'id_token',
},
....

关于amazon-cognito - AWS Cognito 外部用户池身份提供商 (OIDC),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61514231/

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