google-api-dotnet-client icon indicating copy to clipboard operation
google-api-dotnet-client copied to clipboard

GoogleWebAuthorizationBroker.AuthorizeAsync keeps on hanging when it is hosted on IIS

Open nandakishoregn opened this issue 9 years ago • 12 comments

GoogleWebAuthorizationBroker.AuthorizeAsync is not working when hosted on IIS. But, we can authorize in local (Visual Studio 2015).

nandakishoregn avatar Dec 20 '16 10:12 nandakishoregn

please define not working.

Assuming that you are using Filedatastore ensure that IIS has access to write to what ever directory you are storing your credentials.

LindaLawton avatar Dec 20 '16 12:12 LindaLawton

Thanks for the response. But, I have given full access for that folder new FileDataStore(@"C:\inetpub\wwwroot\TempFiles", true) The code what i've used is UserCredential oCredential = GoogleWebAuthorizationBroker.AuthorizeAsync( (new ClientSecrets() { ClientId = sGDClientID, ClientSecret = sGDClientSecret }), Scopes, HttpContext.Current.User.Identity.Name, System.Threading.CancellationToken.None, new FileDataStore(@"C:\inetpub\wwwroot\TempFiles", true) ).Result;

The application keeps on loading, When I do GoogleWebAuthorizationBroker.AuthorizeAsync and I've captured the exception at System.Threading.Monitor.ObjWait(Boolean exitContext, Int32 millisecondsTimeout, Object obj) at System.Threading.ManualResetEventSlim.Wait(Int32 millisecondsTimeout, CancellationToken cancellationToken) at System.Threading.Tasks.Task.SpinThenBlockingWait(Int32 millisecondsTimeout, CancellationToken cancellationToken) at System.Threading.Tasks.Task.InternalWait(Int32 millisecondsTimeout, CancellationToken cancellationToken) at System.Threading.Tasks.Task`1.GetResultCore(Boolean waitCompletionNotification) at btnConnectGoogleDrive_Click(Object sender, EventArgs e)

It works in Local VS2015, It opens new tab for authentication. But, it doesnot work when hosted in IIS. i'm using version Google.Apis.Auth.1.20.0

nandakishoregn avatar Dec 20 '16 12:12 nandakishoregn

I am far from an IIS expert but I would also check that you are blocking the calls from Google it all goes though port 80 or maybe 8080.

https://accounts.google.com/o/oauth2/auth https://accounts.google.com/o/oauth2/token

new ones are for openIdConnect complaints:

accounts.google.com/o/oauth2/v2/auth www.googleapis.com/oauth2/v4/token

If that doesnt help i would take your question to stackoverflow someone there should be able to assist you in debugging IIS issues.

LindaLawton avatar Jan 02 '17 10:01 LindaLawton

another one related to this just poped up on stack ASP.NET MVC communication with Google API to get Oauth authentication

LindaLawton avatar Jan 20 '17 13:01 LindaLawton

Hi I have also faced this problem. I have also tried to make a custom IDataStore class but it complains for access denied. @nandakishoregn has mentioned this. When I changed the property of the project from IIS Express server to Local IIS server I also faced the same problem.

clifflo avatar Jan 20 '17 15:01 clifflo

Hi,

Did any one having the solution for this issue?

rajab0502 avatar Mar 20 '17 14:03 rajab0502

I have someone willing to help get me going on IIS so that i can try and debug the GoogleWebAuthorizationBroker is not working from IIS Host issue.

He sent me a sample project with the issue and i am going to see if i cant figure out whats going on. He is also helping me with IIS as its probably been five years since i have done any web dev.

LindaLawton avatar Mar 24 '17 12:03 LindaLawton

Hello!

I had such problem when I implemented own DataStore with EntityFramework. And I also called AuthorizeAsync with ").Result;". And deadlock will occur in such situation. I resolved this issue by adding ConfigureAwait(false) for each async call of Entity Framework. For example: await ((DbContext)_context).SaveChangesAsync().ConfigureAwait(false);

Maybe it is the same problem, maybe is not.

-- Regards, Oleksii

oleksii-bielik avatar Mar 24 '17 14:03 oleksii-bielik

I tried creating an EntityframeworkDatastore as well. As far as i can see its hanging on spawning the auth webpage. I put this up on stack hoping for someone with more IIS knowledge then me answering it.

IIS cant spawn new process

LindaLawton avatar Mar 28 '17 08:03 LindaLawton

GoogleWebAuthorizationBroker is for use in an application that is running locally on an end-user machine. It opens a web browser locally allowing the user to authenticate. It sounds like you are trying to use GoogleWebAuthorizationBroker on a server machine, from within IIS; where it won't work, as it will try to open a web browser on that server machine - this will fail, and wouldn't be visible to the end-user anyway as it'll be on the server machine, not their machine.

I've not done this myself, but it looks like the instructions here (for an ASP.NET MVC web app) might help.

chrisdunelm avatar Mar 30 '17 14:03 chrisdunelm

Looks like GoogleWebAuthorizationBroker was being mis-used; so closing.

If this wasn't the case, please re-open with more information.

chrisdunelm avatar Apr 18 '17 13:04 chrisdunelm