I am developing a web application in ASP.NET MVC (C #), which works with the Google Drive API. I've gotten the whole issue of authentication using OAuth 2.0 and I'm working perfectly with the API. The problem is that after logging in and giving my application permissions to work, if I access the URL of my website from another computer, it does not ask for authorization, but instead works with the account that had already been authenticated at first.
In other words, I need to be able to access my website and work with Google Drive with different user accounts. Where everyone authenticates and works with their Google Drive.
The code is the following:
public static Google.Apis.Drive.v3.DriveService GetService_v3()
{
UserCredential credential;
using (var stream = new FileStream(HostingEnvironment.MapPath("~/client_secret.json"), FileMode.Open, FileAccess.Read))
{
String FolderPath = HostingEnvironment.MapPath("~");
String FilePath = Path.Combine(FolderPath, "DriveServiceCredentials.json");
credential = GoogleWebAuthorizationBroker.AuthorizeAsync(
GoogleClientSecrets.Load(stream).Secrets,
Scopes,
"user",
CancellationToken.None,
new FileDataStore(FilePath, true)).Result;
}
//Create Drive API service.
Google.Apis.Drive.v3.DriveService service = new Google.Apis.Drive.v3.DriveService(new BaseClientService.Initializer()
{
HttpClientInitializer = credential,
ApplicationName = "GoogleDriveRestAPI-v3",
});
return service;
}