Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to destroy google drive token after task done?

I am able to authenticate and perform actions on google drive using credential I got after authentication but this token is there for long long time. it says expires-in : 3600 so it should expire in 1hour but when I tried it after a month it uses that token and it worked.

My requirement is after authentication and whatever task is being performed get complete, it should again ask for authentication to user if user initiate the program again. so basically I don't want token to be stored in client's system. Expires-in is not working for me as token get refreshed and is not asking again for Authentication.

below is my code which I am using :

credential = GoogleWebAuthorizationBroker.AuthorizeAsync(
                   new ClientSecrets
                   {
                       ClientId = "<myid>.apps.googleusercontent.com",
                       ClientSecret = "<Mysecret>"
                   },
                   new[] { DriveService.Scope.Drive },
                   "user",
                   CancellationToken.None).Result;

                // Create the service using the client credentials.
                DriveService service = new DriveService(new BaseClientService.Initializer()
                     {
                         HttpClientInitializer = credential,
                         ApplicationName = "sampleapp"
                     });
*****some task performed*********

now after this "some task" I want token to be destroy.

Please help.

like image 535
user2376920 Avatar asked May 26 '14 17:05

user2376920


People also ask

How do I invalidate a Google token?

Revocation methods Users log in to their Google Account, find your app in the Third-party apps with account access settings and select Remove Access. Your platform calls google.accounts. id. revoke .

How do I revoke a token in oauth2?

To revoke a refresh token, send a POST request to https://YOUR_DOMAIN/oauth/revoke . The /oauth/revoke endpoint revokes the entire grant, not just a specific token. Use the /api/v2/device-credentials endpoint to revoke refresh tokens.


1 Answers

From release 1.8.2 (http://google-api-dotnet-client.blogspot.com/2014/05/announcing-release-of-182.html) which was just released earlier today, we support token revocation. It revokes the token and also deletes it form the data store.

All you have to do is the following:

await credential.RevokeTokenAsync(CancellationToken.None);

As simple as that.

UPDATE: Read more about token revocation in the Google APIs client library for .NET in this blogpost: http://peleyal.blogspot.com/2014/06/182-is-here.html

like image 52
peleyal Avatar answered Sep 29 '22 22:09

peleyal