I let Google drive users log in and make use of their google drive data. However, only the first user need to authenticate and the following users get access to the first users data! What is wrong in this code?
public static DriveService GetService()
{
//get Credentials from client_secret.json file
UserCredential credential;
var path = HttpContext.Current.Server.MapPath(@"~/client_secret.json");
using (var stream = new FileStream(path, FileMode.Open, FileAccess.Read))
{
// The file token.json stores the user's access and refresh tokens, and is created
// automatically when the authorization flow completes for the first time.
string credPath = HttpContext.Current.Server.MapPath(@"~/token.json");
credential = GoogleWebAuthorizationBroker.AuthorizeAsync(
GoogleClientSecrets.Load(stream).Secrets,
Scopes,
"user",
CancellationToken.None,
new FileDataStore(credPath, true)).Result;
}
//create Drive API service.
DriveService service = new DriveService(new BaseClientService.Initializer()
{
HttpClientInitializer = credential,
ApplicationName = "GoogleDriveRestAPI-v3",
});
return service;
}
It worked but the account got bound to the server and all potential users would have got access to the same account.
The way the client library works is that it stores the users credentials in credpath. each user is denoted by the user you are saying it is "user",
your code is only setting one "user", so its going to load the single user each time.