ASP.NET MVC5 Google APIs GoogleWebAuthorizationBro

2020-03-26 08:31发布

问题:

I'm having an odd problem trying to get an MVC5 app to work with the Google Mirror API when it's deployed (or any google API for that matter).

This is the code I am struggling to get working:

UserCredential credentials = GoogleWebAuthorizationBroker.AuthorizeAsync(
    new ClientSecrets
    {
        ClientId = "my_client_id",
        ClientSecret = "my_client_Secret"
    },
    new[] { MirrorService.Scope.GlassTimeline }, 
    "username", 
    CancellationToken.None,
    new GlassDataStore()
).Result;

When I run this locally from Visual Studio 2013, everything works perfectly - the above code runs and authenticates, persists to the database and I can continue as normal sending cards etc.

Whenever I deploy this to a "real" server however (mostly to get Subscriptions working) it just hangs forever when the above code is executed. I've setup remote debugging and can see that the code does actually run without an exception, but seems to just stop immediately afterwards.

In the browser the page just sits there loading after this code is called (from a button in this case) and w3p.exe starts to eat memory (Fairly slowly, but its an upwards trend..)

It's been frustrating me all weekend - i've tried so many solutions including implementing the code with the guts of GoogleWebAuthorizationBroker as its really just a helper class, but I see the exact same result.

I've tried deploying to two different servers, and checked that the web.configs are the same each time etc.

Any suggestions? I am expecting this to be something really simple that i've missed, and to be a config issue..given that it works locally.

THanks!

edit: Reading around It appears that using the WebAuthorizationBroker may not be the best way to do it in MVC - I should be doing it manually with GoogleAuthorizationCodeFlows..I will try that in the morning, but still - using the broker works fine on an MVC5 site running in VS2013, so I am stumped!

回答1:

I'm closing this question now - the end answer was to use GoogleAuthorizationCodeFlows to do it properly, all working well now :)

The method I describe in my question is no longer supported by Google.