Is it possible to authenticate a user using only user pool credentials without an identity pool/IdentityPoolId? Check out this link for more information: https://github.com/aws/amazon-cognito-identity-js
The example provided in the link above specifically requires an identity pool to work. When calling the method:
cognitoUser.changePassword('oldPassword', 'newPassword', function(err, result) {}
An error is returned from CognitoUser.js (string 602-604). The code snippet checks if the user session is valid before proceeding.
If (!(this.signInUserSession != null && this.signInUserSession.isValid())) {
return callback(new Error('User is not authenticated'), null);
}
In contrast, when calling:
cognitoUser.getSession(function(err, session) {if (err) {
alert(err);
return;
}
console.log('session validity: ' + session.isValid());
The session tokens are successfully retrieved.
To authenticate the user without relying on an identity pool, I have attempted the following approach:
const logins = {};
logins['cognito-idp.' + environment.region + '.amazonaws.com/' + environment.UserPoolId] = session.getIdToken().getJwtToken();
AWS.config.credentials = new AWS.CognitoIdentityCredentials({
Logins: logins
});
However, this results in an error:
Argument of type '{ Logins: {}; }' is not assignable to parameter of type 'CognitoIdentityOptions'.
My goals are:
1) How can I determine if a Cognito userpool user is authenticated without using an Identity Pool?
2) What is the proper way to authenticate a user under these circumstances?
3) The CognitoUser object has two properties:
- Session
- signInUserSession
What are their purposes and how should they be utilized correctly?
P.S. Although everything functions as expected when utilizing an identity pool, my objective is to accomplish authentication without its dependency like so:
const creds = new AWS.CognitoIdentityCredentials({
IdentityPoolId: environment.IdentityPoolId,
Logins: {
[`cognito-idp.${environment.region}.amazonaws.com/${environment.UserPoolId}`]: session.getIdToken().getJwtToken()}},
{
region: environment.region
});
AWS.config.credentials = creds;