我是aws认知的新手。这是我想要做的:用户认证检查使用sts令牌而不是用户/ pass
我有一些用户,我希望他们登录到我的网站,然后就他们的会话有效我想保持他们在没有强迫他们登录。所以据我所知,我需要使用cognito生成STS令牌并发送给用户,然后在接下来的调用中,用户将发送sts令牌作为头,并使用cognito检查sts令牌,如果有效,我将为用户。
对于我使用的指令在下面的链接:
https://github.com/aws/amazon-cognito-identity-js/
那么具体的我用这部分对用户进行认证和建立会话:
var authenticationData = {
Username : 'username',
Password : 'password',
};
var authenticationDetails = new AWSCognito.CognitoIdentityServiceProvider.AuthenticationDetails(authenticationData);
var poolData = {
UserPoolId : '...', // Your user pool id here
ClientId : '...' // Your client id here
};
var userPool = new AWSCognito.CognitoIdentityServiceProvider.CognitoUserPool(poolData);
var userData = {
Username : 'username',
Pool : userPool
};
var cognitoUser = new AWSCognito.CognitoIdentityServiceProvider.CognitoUser(userData);
cognitoUser.authenticateUser(authenticationDetails, {
onSuccess: function (result) {
console.log('access token + ' + result.getAccessToken().getJwtToken());
//POTENTIAL: Region needs to be set if not already set previously elsewhere.
AWS.config.region = '<region>';
AWS.config.credentials = new AWS.CognitoIdentityCredentials({
IdentityPoolId : '...', // your identity pool id here
Logins : {
// Change the key below according to the specific region your user pool is in.
'cognito-idp.<region>.amazonaws.com/<YOUR_USER_POOL_ID>' : result.getIdToken().getJwtToken()
}
});
// Instantiate aws sdk service objects now that the credentials have been updated.
// example: var s3 = new AWS.S3();
},
onFailure: function(err) {
alert(err);
},
});
到目前为止好。但是,现在在任何后续调用我不想送
var authenticationData = {
Username : 'username',
Password : 'password',
};
,而是我想用STS令牌来验证用户的身份:
var authenticationData = {
sts: 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'
};
var authenticationDetails = new AWSCognito.CognitoIdentityServiceProvider.AuthenticationDetails(authenticationData);
我没有看到任何实例或使用这样的情况。 cognito是这种情况下的正确服务,如果是的话,我该如何使用sts进行身份验证检查?