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.
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 .
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With