我查看了类似的问题,但无法解决我的问题.我正在开发一个Web应用程序,用户将使用AWS Cognito的身份验证进行身份验证.注册部分没问题,但是当我尝试登录时,我收到了"未授权"的例外情况.我已经尝试将自定义策略附加到我的IAM角色(授权sts:AssumeRoleWithWebIdentity),但是没有用.以下是代码的编写方式:
var cognitoUser = new AWSCognito.CognitoIdentityServiceProvider.CognitoUser(userData);
cognitoUser.authenticateUser(authenticationDetails, {
onSuccess: function (result) {
var sts = new AWS.STS({apiVersion: '2011-06-15'});
var params = {
RoleArn: 'arn:aws:iam::981601120657:role/Cognito_AliceAuth_Role', /* required */
RoleSessionName: 'AliceUserSession',
WebIdentityToken: result.getIdToken().getJwtToken(),
Policy: '{ "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": "sts:AssumeRoleWithWebIdentity", "Resource": "*" } ] }'
};
sts.assumeRoleWithWebIdentity(params, function (err, data) {
if (err)
console.log(err, err.stack); // ** <-- ERROR HERE
else
console.log(data); // successful response
});
//document.getElementById('authForm').submit();
},
onFailure: function (err) {
alert(err);
}
});
Run Code Online (Sandbox Code Playgroud)
如您所见,我也在代码中指定了策略,但我仍然得到"AccessDenied:未授权执行sts:AssumeRoleWithWebIdentity"错误.请帮我 :/ …