Search code examples
c#asp.net-mvcgoogle-oauthgoogle-api-dotnet-clientadsense-api

ASP.NET MVC5 Google APIs GoogleWebAuthorizationBroker.AuthorizeAsync not work in server


ASP.NET MVC5 Google APIs GoogleWebAuthorizationBroker.AuthorizeAsync AdSense Management API, works locally but not in server,,

GoogleWebAuthorizationBroker.Folder = "Google.Apis.Auth";

                var credential = GoogleWebAuthorizationBroker.AuthorizeAsync(
                    new ClientSecrets
                    {
                        ClientId = "XXXX",
                        ClientSecret = "XXXX"
                    },
                    new string[] { AdSenseService.Scope.Adsense },
                    "SampleApp",
                    CancellationToken.None).Result;

                var service = new AdSenseService(new BaseClientService.Initializer()
                {
                    HttpClientInitializer = credential,
                });

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.


Solution

  • Have you changed your redirect URI to point to your application's auth endpoints.

    While testing on your local it was/is most probaly set to something like http://localhost:8080, where as on your server it should be set to something like: http://example.com/oauth2callback

    Using OAuth 2.0 for Web Server Applications