asp.net identity 2.1 google authentication

Feb 17, 2015 at 12:51 PM
I'm using trying to use Google authentication in an ASP.NET MVC application.
For testing purposes I'm using the template app generated by VS2013 Update 4

In Google settings the return URLs are properly set and Google+ API is turned on

It works fine when I publish the app to an azure website. I can login using Google accounts without any problems.

However I'd like to deploy it on premises but here we have a reverse proxy setup which works like this:
  • the server sees itself as server01.mysite.com but this is an internal name
  • outside world sees it as www.mysite.com (certain paths are reverese proxied to the server01.mysite.com
Essentially www.mysite.com/myapp is reverse proxied to server01.mysite.com/myapp

With this setup I can't seem to use Google authentication. GetExternalLoginInfoAsync returns null and the app redirects itself to the login page.

By default the system generates a redirectUri using the private hostname. I tried changing it to the public address but this does not solve the problem.
Below is what I did at startup.auth.cs
            app.UseGoogleAuthentication(new GoogleOAuth2AuthenticationOptions()
            {
                ClientId = "...",
                ClientSecret = "...",

                Provider = new GoogleOAuth2AuthenticationProvider
                {
                    OnApplyRedirect = context =>
                    {
                        var redirectUri = context.RedirectUri.Replace("server01", "www");
                        context.Response.Redirect(redirectUri);
                    },
                }
            });

Is there anyway I can make Google authentication work in a setup like this?



Thanks