I am using ASP.NET Web API and Google.Apis.Drive.v2 Client Library for .NET to upload files to users Drive.
All examples of using the Drive Client Library for .NET require a authentication flow. But how should I create the DriveService when I already know the access token?
Normally when you access Google Drive using oauth2 you would do something like this
This creates a
UserCredential
that you can then use to create aDriveService
The problem you are going to have is that
FileDataStore
stores the credential information on the hard drive. in the%AppData%
directory.What you want to do is create your own implementation of IDataStore and use that instead. The code to do this is extensive. The closest example I have at the moment is one that will load the refresh token from the database. I haven't had time to create a tutorial to go along with this but the project is siting on GitHub. Google-Dotnet-Samples/Authentication you are welcome to play around with it. I would check out the database one you should be able to alter it to let you submit a refreshtoken to it.
Despite the fact that have been 2 years since the question has been asked, today I've encountered the same situation and my solution is: