Authentication 是什么原因引起的;“不正确的代币观众”;在AWS中使用Google身份验证令牌
我正在创建一个简单的web应用程序,它将使用Google身份验证返回OpenID令牌,然后使用javascript WebIdentityCredentials将该令牌传递给AWS 我所做的:Authentication 是什么原因引起的;“不正确的代币观众”;在AWS中使用Google身份验证令牌,authentication,amazon-web-services,oauth-2.0,google-plus,google-openid,Authentication,Amazon Web Services,Oauth 2.0,Google Plus,Google Openid,我正在创建一个简单的web应用程序,它将使用Google身份验证返回OpenID令牌,然后使用javascript WebIdentityCredentials将该令牌传递给AWS 我所做的: 创建了Google项目,并保存了OAuth客户端ID 使用GoogleIDP和OAuthClientID创建了一个IAM角色作为受众字段 在上面配置的网页中包括Google API和AWS API javascript (客户端)使用Google js api从Google请求id令牌 在WebIdent
<ErrorResponse xmlns="https://sts.amazonaws.com/doc/2011-06-15/">
<Error>
<Type>Sender</Type>
<Code>InvalidIdentityToken</Code>
<Message>Incorrect token audience</Message>
</Error>
<RequestId>28d09368-bf98-11e5-b52f-953b4c773ebf</RequestId>
</ErrorResponse>
以下是AWS的角色:
{
"Version": "2012-10-17",
"Statement": [{
"Effect": "Allow",
"Principal": {"Federated": "accounts.google.com"},
"Action": "sts:AssumeRoleWithWebIdentity",
"Condition": {
"StringEquals": {
"accounts.google.com:aud": "<my-oauth-client-id>"
}
}
}
]
}
我已经使用jwt.io验证了id令牌,我可以看到它具有正确的预期字段。“aud”和“azp”属性具有OAuth客户端ID。我还仔细检查了AWS角色中的Trust stansza,以确认它在条件中也具有完全相同的OAuth客户端ID
我传入了其他无效的令牌并更改了RoleArn,只是为了查看不同的错误,我确实这么做了
我在网上找不到任何描述“不正确的代币观众”原因的东西,所以我不知道下一步该怎么做 我能够通过删除为Cognito设置的标识提供者来克服这个错误。但我仍然不知道为什么会出现这个问题。如果有人知道答案,“什么原因…”这个问题仍然有效。我也有同样的问题。。。
AWS.config.update({
region: 'us-east-1',
credentials: new AWS.WebIdentityCredentials({
RoleArn: 'arn:aws:iam::<my-acct>:role/lab-amp-google-idp',
WebIdentityToken : token
})
});
AWS.config.credentials.get(function(err) {
if (err) console.log(err);
else console.log(AWS.config.credentials);
});