2014-09-02 57 views
1

我已经部署MVH 5站点到AppHarbor,得到了https-only应用程序的工作感谢this gist由AppHarbor支持链接。redirect_uri_mismatch与https-only应用程序AppHarbor

当我在本地连接到Google OAuth 2提供程序时,一切正常 - 我可以毫无问题地登录,但是当我在AppHarbor上尝试时,出现登录错误“redirect_uri_mismatch”。我有适当的密钥和秘密集的Web应用程序,问题是与路径,由于某种原因,我的网页响应与redirect_uri“http:// ...”而不是“https:// ...”开始我已经设置在谷歌项目控制台 - (除了它是相同的uri)。

我试过this workaround基于URL的问题,但它似乎没有改变任何东西。

因为我不认为切换到/ signin-google的http将是一个好主意 - 如何解决它?

+0

你使用的是Google .net客户端库吗? – DaImTo 2014-09-03 07:18:04

+0

不,用于远程授权的默认MVC5库,是Katana项目的一部分。以下是我用过的教程:http://www.asp.net/mvc/tutorials/mvc-5/create-an-aspnet-mvc-5-app-with-facebook-and-google-oauth2-and- openid-sign-on - 它使用Microsoft.Owin.Security.Google库:http://msdn.microsoft.com/en-us/library/microsoft.owin.security.google%28v=vs.113%29.aspx – 2014-09-03 13:20:19

+0

我花了好几个月试图让Microsoft.Owin.Security.Google工作。我放弃。如果你确实得到它的工作,请发布代码。 – DaImTo 2014-09-03 13:22:45

回答

3

这是几个月后,但我希望这将有助于某人。我与AppHarbor负载均衡器的问题完全相同,并在redirect_uri字符串中丢失了“https”。我发现的最简单的解决方案是外部登录提供者的任何注册之前登记的像在Startup.Auth.cs中间件几行代码:

 app.Use(async (context, next) => 
     { 
      if (string.Equals(context.Request.Headers["X-Forwarded-Proto"], "https", StringComparison.InvariantCultureIgnoreCase)) 
      { 
       context.Request.Scheme = "https"; 
      } 

      await next.Invoke(); 
     }); 

这个简单的中间件检查AppHarbor标题“X-Forwarded- Proto“,如果存在,只需添加一个正确的Scheme属性。如果你看看Katana's code正确的Scheme属性解决问题:

... 
    string requestPrefix = Request.Scheme + "://" + Request.Host; 
    string redirectUri = requestPrefix + Request.PathBase + Options.CallbackPath; 
    ...