use*_*920 5 c# google-drive-api google-oauth google-api-dotnet-client
我可以使用我在身份验证后获得的凭据对Google驱动器进行身份验证和执行操作,但此令牌已存在很长时间.它说expours-in:3600所以它应该在1小时内到期但是当我在一个月之后尝试它它使用那个令牌并且它起作用了.
我的要求是在身份验证之后,无论正在执行的任务是否完成,如果用户再次启动程序,它应该再次向用户请求身份验证.所以基本上我不希望令牌存储在客户端的系统中.Expires-in对我来说不起作用,因为令牌被刷新并且不再要求身份验证.
下面是我正在使用的代码:
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*********
Run Code Online (Sandbox Code Playgroud)
现在在这个"一些任务"之后,我想让令牌被摧毁.
请帮忙.
从今天早些时候刚刚发布的1.8.2版本(http://google-api-dotnet-client.blogspot.com/2014/05/announcing-release-of-182.html)开始,我们支持令牌撤销.它撤销令牌并从数据存储中删除它.
您所要做的就是以下内容:
await credential.RevokeTokenAsync(CancellationToken.None);
Run Code Online (Sandbox Code Playgroud)
就如此容易.
更新:在此博客文章中阅读有关.NET的Google API客户端库中令牌撤销的更多信息:http://peleyal.blogspot.com/2014/06/182-is-here.html