我是通过javascript在网页中完成的。
首先,我将用户发送给Google,以便他们可以授予访问权限:
https://accounts.google.com/o/oauth2/auth?response_type=token&scope=profile&redirect_uri=https://example.com/&client_id=1414xxxxxxxx-{myclientid}.apps.googleusercontent.com
授予访问权限后,会将其重定向回我的网站,如下所示:
https://example.com/#access_token={their_token}&token_type=Bearer&expires_in=3600
然后我将这些信息提供给亚马逊,如下所示:
// Initialize the Amazon Cognito credentials provider
AWS.config.credentials = new AWS.CognitoIdentityCredentials({
IdentityPoolId: 'us-east-1:{my-pool-id}',
Logins: {
'accounts.google.com': "{their_token}"
}
});
AWS.config.region = 'us-east-1';
AWS.config.credentials.get(function(err) {
if ( err ) {
console.log(err);
}
else {
console.log("ID: "+identityId:AWS.config.credentials.identityId);
}
});
我总是在控制台中出现错误:
"Error: Invalid login token."
标识池'us-east-1:{my-pool-id}'在我的亚马逊控制台中设置,其中包含身份验证提供商的“Google+”设置以及与Google网址中匹配的Google客户端ID(即。 1414xxxxxxxx- {myclientid} .apps.googleusercontent.com)。
我还尝试将参数中的AccountId
和RoleArn
设置为 CognitoIdentityCredentials ,但在这种情况下它没有帮助。 我正确使用Logins
参数吗?我错过了什么?
如果我取出Logins
参数或将其设置为空对象,我会得到一个identityId
,我认为它与未经身份验证的角色相关联。 如何使用Google API作为令牌提供商获取经过身份验证的角色的身份?