如何将认证用户更改为Google Drive API

时间:2021-04-09 15:23:17

I have followed .NET Quickstart tutorial to fetch the drive name list from the Google Drive.

我已按照.NET快速入门教程从Google云端硬盘中获取驱动器名称列表。

This code is working fine. however, I want to know if I can force the authentication again (something like log out, but I think google isn't call it like that).

这段代码工作正常。但是,我想知道我是否可以再次强制进行身份验证(例如注销,但我认为谷歌不会这样称呼它)。

Currently I need to wait the consent to time out in order to select another account.

目前,我需要等待同意超时才能选择其他帐户。

(If I start the application first time or the previous session has timed out, a Google consent page will be prompted so that I can select or add a particular account to authenticate).

(如果我是第一次启动应用程序或上次会话超时,将会提示Google同意页面,以便我可以选择或添加特定帐户进行身份验证)。

I am using OAuth2 and the platform is .NET window form application.

我使用的是OAuth2,平台是.NET窗口表单应用程序。

1 个解决方案

#1


0  

It helps if you post all of your code wrather then just linking a tutorial you followed.

如果你发布所有代码,然后只是链接你所遵循的教程,它会有所帮助。

The way the Google API dotnet client library works is that it stores the user credentials in a datastore on your machine. In the following section of code "user" denotes a users credentials if you change that you can force it to swap between users. If a user does not have credentials then it will pop up and ask you for authentication again. To fully understand how filedata store works I recommend you read my tutorial on the subject Google .net – FileDatastore demystified

Google API dotnet客户端库的工作方式是将用户凭据存储在计算机的数据存储中。在下面的代码部分中,“user”表示用户凭据,如果更改,则可以强制它在用户之间切换。如果用户没有凭据,则会弹出并再次要求您进行身份验证。要完全了解filedata商店如何运作,我建议您阅读我的主题Google .net - FileDatastore deysystified

credential = GoogleWebAuthorizationBroker.AuthorizeAsync(
                GoogleClientSecrets.Load(stream).Secrets,
                Scopes,
                "user",
                CancellationToken.None,
                new FileDataStore(credPath, true)).Result;

In the world of Oauth there really is no such thing as logging out. Technically speaking you have access to a users data until they remove that access or something happens to your refresh token. It will be up to you to change the "user" in your code to make it appear that the user has logged out on your site. The only thing that is close to this is Revoking the token which is basically removing your access to a users data. the user will have to authenticate your application again if they chose to login again.

在Oauth的世界里,确实没有退出的东西。从技术上讲,您可以访问用户数据,直到他们删除该访问权限或刷新令牌发生了什么。您可以自行更改代码中的“用户”,使其看起来已经在您的网站上注销。唯一接近这一点的是撤销令牌,该令牌基本上删除了对用户数据的访问权限。如果用户选择再次登录,则必须再次对您的应用程序进行身份验证。

#1


0  

It helps if you post all of your code wrather then just linking a tutorial you followed.

如果你发布所有代码,然后只是链接你所遵循的教程,它会有所帮助。

The way the Google API dotnet client library works is that it stores the user credentials in a datastore on your machine. In the following section of code "user" denotes a users credentials if you change that you can force it to swap between users. If a user does not have credentials then it will pop up and ask you for authentication again. To fully understand how filedata store works I recommend you read my tutorial on the subject Google .net – FileDatastore demystified

Google API dotnet客户端库的工作方式是将用户凭据存储在计算机的数据存储中。在下面的代码部分中,“user”表示用户凭据,如果更改,则可以强制它在用户之间切换。如果用户没有凭据,则会弹出并再次要求您进行身份验证。要完全了解filedata商店如何运作,我建议您阅读我的主题Google .net - FileDatastore deysystified

credential = GoogleWebAuthorizationBroker.AuthorizeAsync(
                GoogleClientSecrets.Load(stream).Secrets,
                Scopes,
                "user",
                CancellationToken.None,
                new FileDataStore(credPath, true)).Result;

In the world of Oauth there really is no such thing as logging out. Technically speaking you have access to a users data until they remove that access or something happens to your refresh token. It will be up to you to change the "user" in your code to make it appear that the user has logged out on your site. The only thing that is close to this is Revoking the token which is basically removing your access to a users data. the user will have to authenticate your application again if they chose to login again.

在Oauth的世界里,确实没有退出的东西。从技术上讲,您可以访问用户数据,直到他们删除该访问权限或刷新令牌发生了什么。您可以自行更改代码中的“用户”,使其看起来已经在您的网站上注销。唯一接近这一点的是撤销令牌,该令牌基本上删除了对用户数据的访问权限。如果用户选择再次登录,则必须再次对您的应用程序进行身份验证。