Jerald
Jerald

Reputation: 4048

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?

Upvotes: 3

Views: 6060

Answers (2)

Jeff Bailey
Jeff Bailey

Reputation: 5775

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

Upvotes: 1

UXDart
UXDart

Reputation: 2620

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

Upvotes: 1

Related Questions