我能够使用身份验证后获得的凭据对 google drive 进行身份验证和执行操作,但此 token 存在很长时间。它说 expires-in : 3600 所以它应该在 1 小时内过期但是当我在一个月后尝试它时它使用该 token 并且它有效。
我的要求是在身份验证之后,无论正在执行的任务是否完成,如果用户再次启动程序,它应该再次要求用户进行身份验证。所以基本上我不想将 token 存储在客户的系统中。 Expires-in 对我不起作用,因为 token 会刷新并且不会再次要求身份验证。
下面是我正在使用的代码:
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*********
现在在这个“一些任务”之后我想要销毁 token 。
请帮忙。
最佳答案
从今天早些时候发布的 1.8.2 版 (http://google-api-dotnet-client.blogspot.com/2014/05/announcing-release-of-182.html) 开始,我们支持 token 撤销。它撤销 token 并将其从数据存储中删除。
您只需执行以下操作:
await credential.RevokeTokenAsync(CancellationToken.None);
就这么简单。
更新: 在这篇博文中阅读有关 .NET 的 Google API 客户端库中 token 撤销的更多信息:http://peleyal.blogspot.com/2014/06/182-is-here.html
关于c# - 任务完成后如何销毁谷歌驱动器 token ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23874990/