Skip to content

Instantly share code, notes, and snippets.

Created July 22, 2015 07:15
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save LindaLawton/7b2280735406ed5df07b to your computer and use it in GitHub Desktop.
OAuth2 Authentication to google Drive with C#
//Scopes for use with the Google Drive API
string[] scopes = new string[] { DriveService.Scope.Drive,
var clientId = "[Client ID]"; // From
var clientSecret = "xxx"; // From
// here is where we Request the user to give us access, or use the Refresh Token that was previously stored in %AppData%
var credential = GoogleWebAuthorizationBroker.AuthorizeAsync(new ClientSecrets { ClientId = clientId,
ClientSecret = clientSecret},
new FileDataStore("Daimto.GoogleDrive.Auth.Store")).Result;
Copy link

b42sonu commented Dec 13, 2016


I am working on C# MVC web application . In this application I am integrating google drive and using Google.Apis (version- For this implementation I have taken the reference from your sample code and have implemented successfully in my application. During testing I have found that it is working fine when I run directly this from visual studio but when I deployed this on IIS (even local IIS) it is not working. After investigation I have found that it is giving problem in authentication and not trigger the authenticate screen with Gmail account. Mainly giving me on this below line :

UserCredential credential = GoogleWebAuthorizationBroker.AuthorizeAsync(new ClientSecrets {ClientId = clientId, ClientSecret = clientSecret} , scopes , userName , CancellationToken.None
, new FileDataStore(folder,true)).Result;

Nothing has happened after this line (no error) . Kindly help me on this . How I can solve this problem? Is there any setting in IIS that I need to set for this ?

Some trouble shooting I already done like :

  1. Given permission to folder (that store the outh response ). Like users .
  2. Tried with both folder default roaming folder and custom folder (for store the outh response)

Let me know if you want more information from my side.

Best regards,
Sunil Sharma

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment