用例:我想使用联邦标识限制对API网关路径的访问。
为此,我需要使用我的ID令牌获取AWS临时凭证。我得到了我的身份证,但我不知道如何使用身份证获取临时凭证。
这是我将身份证令牌传递给Cognito凭证映射
var data = {
UserPoolId: config.cognito.USER_POOL_ID,
ClientId: config.cognito.APP_CLIENT_ID,
};
var userPool = new AmazonCognitoIdentity.CognitoUserPool(data);
var cognitoUser = userPool.getCurrentUser();
if (cognitoUser != null) {
cognitoUser.getSession(function(err, result) {
if (result) {
console.log('You are now logged in.');
// Add the User's Id Token to the Cognito credentials login map.
AWS.config.credentials = new AWS.CognitoIdentityCredentials({
IdentityPoolId: config.cognito.IDENTITY_POOL_ID,
Logins: {
'cognito-idp.ap-south-1.amazonaws.com/ap-south-1_G7YbVxxxx': result.getIdToken().getJwtToken()
}
});
}
});
}
如何获取临时凭证?
谢谢