Rafał Michałuszek
Rafał Michałuszek

Reputation: 84

How to revoke token provided by OAuth from google? NodeJS

I have connected to google plus from my NodeJS application by using oauth2, but how to revoke token/disconnect? I cant find anything in docs for NodeJS.

Upvotes: 1

Views: 2695

Answers (2)

Mayur Upadhyay
Mayur Upadhyay

Reputation: 58

In case access_token expires, revokeToken method returns "Invalid Token Error". At this time we can pass refresh_token (if you have procured it and put it in a persistant storage). So the changes in the code follows as

let token = oauth2Client.credentials.refresh_token;   
oauth2Client.revokeToken(token, function(err, body) {
    //Do something here after checking if err is set or not
});

Upvotes: 0

Bertrand Martel
Bertrand Martel

Reputation: 45432

You can revoke a token with revokeToken function from google.auth.OAuth2 object :

oauth2Client.revokeToken(token, function(err, body) {

});

You also have revokeCredentials function which clear the credential object and revoke the access token inside it :

oauth2Client.revokeCredentials(function(err, body) {

});

Upvotes: 6

Related Questions