我已经完成了文档中的所有步骤,通过email / pwd combo(工作)注册用户池,在身份提供者的身份池和用户池部分配置了FB身份提供程序,并实现了以下代码示例在http://docs.aws.amazon.com/cognito/latest/developerguide/facebook.html找到,并在下面使用我的身份池进行修改。
{代码}
function facebookLogin(){
FB.login(function (response) {
// Check if the user logged in successfully.
if (response.authResponse) {
console.log('You are now logged in.' + response.authResponse.accessToken);
// Add the Facebook access token to the Cognito credentials login map.
AWS.config.credentials = new AWS.CognitoIdentityCredentials({
IdentityPoolId: 'us-east-1:eb997110-50b3-4e40-97ff-fbaf796da9ef',
Logins: {
'graph.facebook.com': response.authResponse.accessToken // cognitouser.idToken
}
});
console.log('Added FB access token to Cognito.');
// Obtain AWS credentials
AWS.config.credentials.get(function(){
//getCurrentUser();
console.log('Got the aws creds.');
});
} else {
console.log('There was a problem logging you in.');
}
});
}
{代码}
我可以单步执行并查看传递给CognitoIdentityCredentials的FB令牌,但没有错误,但用户永远不会在我的身份池或用户池中注册。
我错过了什么吗?
答案 0 :(得分:0)
以下是我用于在AWS中创建联合身份的代码示例
function loadCredentials(identityPool, provider, accessToken) {
var params = {
/*AccountId: window.appInfo.accountId,*/
//RoleArn: window.ap
IdentityPoolId: identityPool,
Logins: {}
};
params.Logins[provider] = accessToken;
AWS.config.credentials = new AWS.CognitoIdentityCredentials(params);
AWS.config.credentials.get(function (err) {
if (err) {
console.log(err.message);
console.log(err.stack);
}
else
{
console.log("Cognito Identity Id: " + AWS.config.credentials.identityId);
console.log("Worked");
}
});
}