Asp.net mvc asp.net identity 2.1谷歌身份验证
我正在尝试在ASP.NETMVC应用程序中使用Google身份验证。 出于测试目的,我正在使用VS2013更新4生成的模板应用程序 在Google设置中,正确设置返回URL并打开Google+API。当我将其发布到azure网站时,该应用程序运行良好。我可以使用谷歌账号登录,没有任何问题 然而,我希望在本地部署它,但这里我们有一个反向代理设置,其工作原理如下:Asp.net mvc asp.net identity 2.1谷歌身份验证,asp.net-mvc,oauth-2.0,google-oauth,asp.net-identity-2,Asp.net Mvc,Oauth 2.0,Google Oauth,Asp.net Identity 2,我正在尝试在ASP.NETMVC应用程序中使用Google身份验证。 出于测试目的,我正在使用VS2013更新4生成的模板应用程序 在Google设置中,正确设置返回URL并打开Google+API。当我将其发布到azure网站时,该应用程序运行良好。我可以使用谷歌账号登录,没有任何问题 然而,我希望在本地部署它,但这里我们有一个反向代理设置,其工作原理如下: 服务器将自己视为server01.mysite.com,但这是一个 内部名称 外界将其视为www.mysite.com(某些路径是 已
- 服务器将自己视为server01.mysite.com,但这是一个 内部名称
- 外界将其视为www.mysite.com(某些路径是 已将reverese代理到server01.mysite.com
app.UseGoogleAuthentication(new GoogleOAuth2AuthenticationOptions()
{
ClientId = "...",
ClientSecret = "...",
Provider = new GoogleOAuth2AuthenticationProvider
{
OnApplyRedirect = context =>
{
var redirectUri = context.RedirectUri.Replace("server01", "www");
context.Response.Redirect(redirectUri);
},
}
});
在这样的设置中,我能让谷歌认证工作吗
感谢要实现这一点,您必须告诉应用程序尽早使用外部URL,以便在构建相关哈希时考虑到这一点。因此,在使用GoogleAuthentication之前,不要更改OnApplyRedirect上的重定向URI,而要调用此选项:
app.Use((context, next) =>
{
context.Request.Host = new HostString(
context.Request.Host.Value.Replace("server01", "www"));
return next();
}
);
并从UseGoogleAuthentication中删除提供程序=
app.UseGoogleAuthentication(new GoogleOAuth2AuthenticationOptions()
{
ClientId = "...",
ClientSecret = "..."
});