我能够成功登录使用 Facebook 进行身份验证的用户。这工作正常,页面按预期重定向到另一个页面。代码如下。
Cognito Identity ID
我的问题是当我在另一个页面上时如何检索用户 ID(或)?(不在同一页,但当我在另一页时)
AWS.config.region='us-east-1';
AWS.config.credentials = new AWS.CognitoIdentityCredentials({
// either IdentityPoolId or IdentityId is required
// See the IdentityPoolId param for AWS.CognitoIdentity.getID (linked below)
// See the IdentityId param for AWS.CognitoIdentity.getCredentialsForIdentity
// or AWS.CognitoIdentity.getOpenIdToken (linked below)
IdentityPoolId: CognitoIdentityPoolId,
// optional, only necessary when the identity pool is not configured
// to use IAM roles in the Amazon Cognito Console
// See the RoleArn param for AWS.STS.assumeRoleWithWebIdentity (linked below)
RoleArn: 'arn:aws:iam::9287589741169:role/Cognito_111Auth_Role',
// optional tokens, used for authenticated login
// See the Logins param for AWS.CognitoIdentity.getID (linked below)
Logins: {
'graph.facebook.com': accessToken
},
// optional name, defaults to web-identity
// See the RoleSessionName param for AWS.STS.assumeRoleWithWebIdentity (linked below)
RoleSessionName: 'web',
expired: 'true'
});
console.log('Refreshing cognito credentials');
AWS.config.credentials.refresh(function(err) {
if (err) {
console.log('Failed to refresh');
return;
} else {
AWS.config.credentials.get(function(err){
if (!err) {
var id = AWS.config.credentials.identityId;
console.log('Cognito Identity ID '+ id);
}
});
var s3 = new AWS.S3();
console.log('Creds '+ s3.config.credentials.sessionToken);
}
});
}