如何在不使用身份池/ IdentityPoolId的情況下對用戶進行身份驗證,僅使用用戶池憑據? https://github.com/aws/amazon-cognito-identity-js使用Cognito用戶池憑證對用戶進行身份驗證
實施例4中鏈接以上僅適用於/與身份池, 當我打電話例如方法
cognitoUser.changePassword('oldPassword', 'newPassword', function(err, result) {}
retrun我從CognitoUser.js誤差,串602-604
if (!(this.signInUserSession != null && this.signInUserSession.isValid())) {
return callback(new Error('User is not authenticated'), null);
}
但是,當我打電話
cognitoUser.getSession(function(err, session) {if (err) {
alert(err);
return;
}
console.log('session validity: ' + session.isValid());
它給我會話令牌。
如何,我想驗證用戶:
const logins = {};
logins['cognito-idp.' + environment.region + '.amazonaws.com/' + environment.UserPoolId] = session.getIdToken().getJwtToken();
// Add the User's Id Token to the Cognito credentials login map.
AWS.config.credentials = new AWS.CognitoIdentityCredentials({
Logins: logins
});
,讓我錯誤
Argument of type '{ Logins: {}; }' is not assignable to parameter of type 'CognitoIdentityOptions'.
我想要實現:
1)如何理解cognito用戶池用戶身份驗證沒有身份池?
2)如何認證用戶?
3)對象CognitoUser有2個propreties:
- 會議
- signInUserSession
又是爲了什麼? 如何正確使用它們?
P.S.當即時通訊使用這種方式,一切工作正常,但我需要達到它沒有身份池
const creds = new AWS.CognitoIdentityCredentials({
IdentityPoolId: environment.IdentityPoolId, // your identity pool id here
Logins: {
// Change the key below according to the specific region your user pool is in.
[`cognito-idp.${environment.region}.amazonaws.com/${environment.UserPoolId}`]: session.getIdToken().getJwtToken()}},
{
region: environment.region
});
AWS.config.credentials = creds;
感謝解釋,問題更新, 的getSession - >給我會話令牌idToken:CognitoIdToken,refreshToken:CognitoRefreshToken,的accessToken:CognitoAccessToken) getCurrentUser() - 給我的用戶從localStorage的 –