AWSCognitoOIDC联合身份不读取访问令牌中的声明。
创始人
2024-09-24 13:30:20
0

可以通过在AWS Cognito控制台中手动添加声明的映射来解决此问题,或者在AWS Lambda函数中使用AWS SDK实现自定义声明映射。以下是使用AWS SDK实现自定义声明映射的示例:

const AWS = require('aws-sdk');
const cognitoidentity = new AWS.CognitoIdentity();

exports.handler = async (event, context) => {
    const accessToken = event.accessToken;
    const identityId = event.identityId;

    const params = {
        IdentityId: identityId,
        Logins: {
            'LOGIN_PROVIDER_NAME': accessToken
        }
    };
    
    const {Credentials} = await cognitoidentity.getCredentialsForIdentity(params).promise();
    const { assumeRoleWithWebIdentity } = new AWS.STS();
    
    const roleArn = 'arn:aws:iam::ACCOUNT_ID:role/ROLE_NAME'; // Replace with actual role ARN
    const sessionName = 'MySession'; // Replace with any session name

    const assumeRoleParams = {
        RoleArn: roleArn,
        RoleSessionName: sessionName,
        WebIdentityToken: accessToken,
        DurationSeconds: 3600,
    };
    
    const { Credentials: WebIdentityCredentials } = await assumeRoleWithWebIdentity(assumeRoleParams).promise();
    
    // Add custom mapping logic for claims
    const customClaims = {
        'custom:Department': 'Marketing'
    };
    
    const {IdentityPoolId} = process.env;
    const { updateIdentityPool } = new AWS.CognitoIdentity({region: 'us-east-1'});
    
    const identityPoolParams = {
        AllowUnauthenticatedIdentities: false,
        IdentityPoolId: IdentityPoolId,
        IdentityProviderConfigs: [
            {
                ProviderName: "LOGIN_PROVIDER_NAME",
                ProviderDetails: {},
                AttributeMapping: {
                    "custom:Department": "department"
                }
            }
        ]
    };
    
    await updateIdentityPool(identityPoolParams).promise();
    
    return {
        statusCode: 200,
        body: JSON.stringify({
            Credentials,
            WebIdentityCredentials
        })
    };
};

相关内容

热门资讯

关于!微信微乐自建房辅助工具,... 关于!微信微乐自建房辅助工具,微乐家乡麻将自建房辅助app(开挂自建房)方法1)微乐家乡麻将自建房辅...
大家学习交流!微信卡五星辅助器... 大家学习交流!微信卡五星辅助器,微乐小程序免费黑科技(开挂自建房)方法1、很好的工具软件,可以解锁游...
三分钟了解!微乐微信自建房辅助... 三分钟了解!微乐微信自建房辅助工具插件,微乐家乡麻将自建房辅助app(开挂自建房)工具1、三分钟了解...
一分钟教会你!微乐家乡麻将自建... 一分钟教会你!微乐家乡麻将自建房辅助app,微乐自建房脚本免费入口(开挂自建房)方法1、用户打开应用...
分享实测!微信微乐自建房辅助工... 分享实测!微信微乐自建房辅助工具,微乐自建房脚本免费入口(开挂自建房)器1、起透看视 微信微乐自建房...
重大通报!微乐自建房辅助工具脚... 重大通报!微乐自建房辅助工具脚本,微乐小程序免费黑科技(开挂自建房)app微乐自建房辅助工具脚本破解...
如何分辨真伪!微乐微信自建房辅... 如何分辨真伪!微乐微信自建房辅助工具插件,微乐小程序免费黑科技(开挂自建房)技巧1、微乐微信自建房辅...
我来教教你!微乐自建房辅助工具... 我来教教你!微乐自建房辅助工具挂,微乐家乡麻将自建房辅助app(开挂自建房)工具1、玩家可以在微乐家...
重大来袭!微乐自建房辅助工具神... 重大来袭!微乐自建房辅助工具神器,微乐小程序免费黑科技(开挂自建房)器1、游戏颠覆性的策略玩法,独创...
带你了解!微信卡五星辅助器,微... 带你了解!微信卡五星辅助器,微乐自建房脚本免费入口(开挂自建房)方法1、带你了解!微信卡五星辅助器,...