• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 949
  • Last Modified:

Google Drive APi does not Authenticate when using in Asp.net

I am trying to use Google Drive API in my Asp.net web app.
I have hosted my on my local ISS and I had deleted the default web site from ISS and put my app in it.
So that I can use the URL "http://localhost"

I am trying to call this method, when I am running it, I am not getting any error the code runs but nothing happens not Consent Screen opens up for permission.

Not sure why this is not working.

public static async Task<bool> AuthenicateWithGoogle()
            ClientSecrets secrets;

            using (var stream = new System.IO.FileStream(CommonFunction.GetFullPath("client_secrets.json",true),
               System.IO.FileMode.Open, System.IO.FileAccess.Read))
                secrets = GoogleClientSecrets.Load(stream).Secrets;

            IDataStore credentialPersistanceStore = getPersistentCredentialStore();
            //UserCredential credential = GoogleWebAuthorizationBroker.AuthorizeAsync(secrets,
            //        SCOPES, getUserId(), CancellationToken.None, credentialPersistanceStore).Result;

            TokenResponse token;

            token = await credentialPersistanceStore.GetAsync<TokenResponse>("465464").ConfigureAwait(false);

            //var credential = new UserCredential(new GoogleAuthorizationCodeFlow(
            //    new GoogleAuthorizationCodeFlow.Initializer
            //    {
            //        ClientSecrets = secrets
            //    }),
            //    getUserId(), token);

            IAuthorizationCodeFlow flow = new GoogleAuthorizationCodeFlow(new GoogleAuthorizationCodeFlow.Initializer
                ClientSecrets = secrets,
                Scopes = new[] { DriveService.Scope.Drive },
                DataStore = new FileDataStore(CommonFunction.GetFullPathForGoogleDataStoreFolder(), true)

            UserCredential credential = new UserCredential(flow, getUserId(), token);

            googleService = new DriveService(new BaseClientService.Initializer
                HttpClientInitializer = credential,
                ApplicationName = AppConstant.GoogleApplicationName

            return true;

Open in new window

1 Solution
David Johnson, CD, MVPOwnerCommented:
//Scopes for use with the Google Drive API
string[] scopes = new string[] { DriveService.Scope.Drive,
// here is where we Request the user to give us access, or use the Refresh Token that was previously stored in %AppData%
UserCredential credential = 
                          .AuthorizeAsync(new ClientSecrets { ClientId = CLIENT_ID
                                                            , ClientSecret = CLIENT_SECRET }

Open in new window

                                          ,new FileDataStore("Daimto.GoogleDrive.Auth.Store")
yadavdepAuthor Commented:

 The example you shared is a console application, here also everything is working on console application.
Not sure what is wrong on Web application
Ilan OlkiesCommented:
I've run in the same issue, what was the solutions you found?
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now