我最近开始使用 AWS 开发工具包以及用户如何在身份池中使用 Cognito 进行身份验证。查询凭据时,我有以下问题:以下方法在多大程度上不同?
- 方法:getId() 和 getCredentialsForIdentity():
const cognitoidentity = new AWS.CognitoIdentity()
var params = {
IdentityPoolId: 'STRING_VALUE', /* required */
AccountId: 'STRING_VALUE',
Logins: {
'<IdentityProviderName>': 'STRING_VALUE',
/* '<IdentityProviderName>': ... */
}
};
cognitoidentity.getId(params, function(err, data) {
if (err) console.log(err, err.stack); // an error occurred
else console.log(data); // successful response
});
var params = {
IdentityId: 'STRING_VALUE', /* required */
CustomRoleArn: 'STRING_VALUE',
Logins: {
'<IdentityProviderName>': 'STRING_VALUE',
/* '<IdentityProviderName>': ... */
}
};
cognitoidentity.getCredentialsForIdentity(params, function(err, data) {
if (err) console.log(err, err.stack); // an error occurred
else console.log(data); // data AccesKeyId,Expiration, SecretKey, SessionToken
});
- 方法:
AWS.config.credentials = new AWS.CognitoIdentityCredentials({
IdentityPoolId: identityPoolId,
Logins:{
'Provider': jwtToken
},
region: "eu-central-1"
});
AWS.config.credentials.get(function(){
// Credentials will be available when this function is called.
const{ accessKeyId} = AWS.config.credentials
const {secretAccessKey} = AWS.config.credentials
const {sessionToken} = AWS.config.credentials
})
两次尝试的凭据不同,SessionToken 相同。第一次尝试获得的 SecretKey 和第二次尝试获得的 SecretAccesKey 有什么区别?
这两种尝试有什么区别?
第一次尝试:使用 GetId 和 GetCredentialsForIdentity 增强简化的 authflow https://docs.aws.amazon.com/cognito/latest/developerguide/authentication-flow.html
我很感激任何帮助:)