Reputation: 731
I have a user pool in Cognito, and right now I'm following https://github.com/aws-amplify/amplify-js/tree/main/packages/amazon-cognito-identity-js to authenticate user. I'm not using Amplify btw.
However in above link, I can only see example of authentication for identity pool.
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(),
},
});
I can't switch IdentityPoolId to UserPoolId in above code, nor did I find CognitoUserCredentials
class in aws-sdk
.
How can I authenticate for User Pool?
Upvotes: 0
Views: 1581
Reputation: 3865
You are looking for the authenticateUser
method.
However in above link, I can only see example of authentication for identity pool.
This exchange happens after the user has been authenticated in the userpool. It takes the ID token that was just granted and sends them to cognito identity pool which returns AWS credentials to access AWS resources directly. If your app doesn't require user's interact directly with AWS then the tokens from the first step are sufficient.
Upvotes: 1
Reputation: 4480
Cognito Identity JS is for identity pools i believe. Here's the javascript method to sign in to user pool and retrieve tokens. https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/CognitoIdentityServiceProvider.html#initiateAuth-property
Upvotes: 0