Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to logout from all providers in AWS Cognito?

I use AWS Cognito authentication in my web application. Users can authenticate using one of the three identity providers: cognito user pool (by username and password), facebook and google. Here is how I get credentials:

AWS.config.credentials = new AWS.CognitoIdentityCredentials({
    IdentityPoolId: identityPoolId,
    Logins: logins
});
AWS.config.credentials.get(err => {
    console.log("Amazon Cognito Identity", 
    AWS.config.credentials.identityId);
});

logins - Object, that can contain tokens from cognito, facebook and google.

What should web application does if user click logout button? I could do userPool.getCurrentUser().signOut() if current user is exists (current user is exists only in cognito username, password authentication) But what should I do if somebody signs in using facebook or google?

like image 962
Ildar Avatar asked Dec 17 '25 13:12

Ildar


2 Answers

that is enough (the sign out), the session token will expire and that user won't be able to login again without using a new token. your cognito pool will still have the provider user.. but that is fine, if you remove it and the user signs in again, it will be a different user, so you need to keep the record in the cognito database

like image 182
UXDart Avatar answered Dec 19 '25 02:12

UXDart


The JS SDK has a method called clearCachedId that should wipe the local state and help with this.

http://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/CognitoIdentityCredentials.html

like image 26
Jeff Bailey Avatar answered Dec 19 '25 02:12

Jeff Bailey



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!