简体   繁体   English

MVC4的问题和Google的外部登录

[英]Problems with MVC4 & External Login with Google

I've an ASP .NET MVC4 application that uses SimpleMembership and allows users to sign in with their google accounts. 我有一个使用SimpleMembership的ASP .NET MVC4应用程序,并允许用户使用其Google帐户登录。

In order to do that I configured the application's AuthConfig class by uncommenting the OAuthWebSecurity.RegisterGoogleClient(); 为此,我通过取消注释OAuthWebSecurity.RegisterGoogleClient();来配置应用程序的OAuthWebSecurity.RegisterGoogleClient();OAuthWebSecurity.RegisterGoogleClient(); line to add google as an external login method. 这行将google添加为外部登录方法。 I didn't really change much inside the external login methods that already come with the ASP .NET MVC4 Internet Application template. ASP .NET MVC4 Internet应用程序模板已经附带的外部登录方法中,我并没有做太多改变。

Problem: 问题:

Everything works fine when I run it locally (IIS express) or when I deploy it to a 'test' server (IIS 6.1, accessible on the intranet only). 当我在本地运行它(IIS express)或将其部署到“测试”服务器(IIS 6.1,仅可在Intranet上访问)时,一切正常。 When I click my "sign in with google" button, I'm sent to google's authentication page, whose url looks something like this: 当我单击“使用google登录”按钮时,我将被发送到google的身份验证页面,其网址如下所示:

https://accounts.google.com/ServiceLogin?service=lso&passive=12096...(long url)

Alas, when I deploy it to the 'production' server (internet facing) and try to access it via internet, Google authentication stops working: when I click my "sign in with google" I'm being sent to an url that looks like this: las,当我将其部署到“生产”服务器(面向Internet)并尝试通过Internet进行访问时,Google身份验证将停止工作:当我单击“使用google登录”时,系统会将我发送到如下网址这个:

http://MY_APPLICATION_NAME.MY_DOMAIN.com/accounts/o8/ud?openid.claimed_id=http%3A%2F%2Fspecs.openid...(long url)

This url is wrong not only because it has my domain in it (I believe it should be accounts.google.com?), but also because the rest of it is completely different from the url I get when the authentication works. 这个网址是错误的,不仅因为其中包含我的域(我认为应该是accounts.google.com?),还因为它的其余部分与身份验证有效时获得的网址完全不同。

What I know and have tried: 我所知道并尝试过的:

If I use fiddler, I can see that the application is behaving differently when I'm accessing the application via internet or intranet. 如果我使用提琴手,当我通过Internet或Intranet访问该应用程序时,可以看到该应用程序的行为有所不同。

  • If I access it from within the network, I see I'm making a request to http://MY_APPLICATION_NAME.MY_DOMAIN.com/account/ExternalLogin?returnUrl= and then "Tunnel to www.google.com:443, Tunnel to accounts.google.com:443" . 如果我是通过网络访问的,则表明我正在向http://MY_APPLICATION_NAME.MY_DOMAIN.com/account/ExternalLogin?returnUrl=发出请求,然后向"Tunnel to www.google.com:443, Tunnel to accounts.google.com:443" This works ok. 这样就可以了。
  • If I access it from the internet I see I'm making a request to http://MY_APPLICATION_NAME.MY_DOMAIN.com/account/ExternalLogin?returnUrl= and then another one to http://MY_APPLICATION_NAME.MY_DOMAIN.com/accounts/o8/ud?openid.claimed_id=http%3A%2F%2Fspecs.openid...(long url) . 如果我从互联网访问它,我看到我正在做一个请求http://MY_APPLICATION_NAME.MY_DOMAIN.com/account/ExternalLogin?returnUrl= ,然后又一个http://MY_APPLICATION_NAME.MY_DOMAIN.com/accounts/o8/ud?openid.claimed_id=http%3A%2F%2Fspecs.openid...(long url) This obviously gives a 404. 这显然给出了404。

I might be wrong but I assume that this url is generated by the OAuthWebSecurity.RequestAuthentication(provider, returnUrl) . 我可能错了,但是我认为此URL是由OAuthWebSecurity.RequestAuthentication(provider, returnUrl) What puzzles me is that it looks like it is requesting the authenticaton to my server instead of accounts.google.com. 让我感到困惑的是,它似乎是在向我的服务器而不是account.google.com请求认证。

My research so far has only brought to me posts/questions/etc. 到目前为止,我的研究仅给我带来了帖子/问题/等等。 showing how easy it is to use SimpleMembership for external authentication and I can see everyone does it pretty much the same way. 显示使用SimpleMembership进行外部身份验证有多么容易,我可以看到每个人都以几乎相同的方式进行操作。

Conclusion: 结论:

I believe this probably has something to do with something I must configure on web.config or IIS. 我相信这可能与我必须在web.config或IIS上配置的内容有关。 I do know that the requests to my application arrive at my DNS server which does a url rewrite and forwards the request to my web server, although I don't know if this is related to the problem. 我确实知道对我的应用程序的请求到达了我的DNS服务器,该服务器进行URL重写并将请求转发到我的Web服务器,尽管我不知道这是否与问题有关。

Does anyone have any idea of what might be wrong or ever had a similar issue? 是否有人对可能出什么问题或曾经有过类似问题有任何想法? Any help would be appreciated. 任何帮助,将不胜感激。

EDIT: 编辑:

I've looked into OpenAuthSecurityManager.cs 's source code and although I can't debug it I see the problem might be related to an incorrect HttpContext inside the RequestAuthentication method, due to my reverse proxy settings on IIS? 我已经研究过OpenAuthSecurityManager.cs的源代码,尽管无法调试它,但由于我在IIS上的反向代理设置,该问题可能与RequestAuthentication方法中的HttpContext错误有关?

I ended up with a request to change the IT infrastructure. 我最终提出了更改IT基础架构的请求。 OpenAuthSecurityManager.cs was probably getting a wrong HttpContext instance because of the way the requests were being handled by the previous infrastructure (requests arrived at our DNS server and were forwarded to the web service, on a different server inside our network, with UrlRerwrite rules). 由于以前的基础结构处理请求的方式,OpenAuthSecurityManager.cs可能收到了错误的HttpContext实例(请求到达了我们的DNS服务器,并使用UrlRerwrite规则转发到了网络内部另一台服务器上的Web服务) 。

It's working now. 现在正在工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM