【问题标题】:Oauth2 response from Google gives DotNetOpenAuth 400 bad requestGoogle 的 Oauth2 响应给出了 DotNetOpenAuth 400 错误请求
【发布时间】:2015-02-05 09:44:18
【问题描述】:

我正在使用 ServiceStack for Google 设置 OAuth2。我在我的 web.config 中注册了 google,如下所示:

 <add key="oauth.GoogleOAuth.ConsumerKey" value="key"/>
    <add key="oauth.GoogleOAuth.ConsumerSecret" value="secretkey"/>     
      <add key="oauth.GoogleOAuth.RedirectUrl" value="myurl/home"/>  
    <add key="oauth.GoogleOAuth.CallbackUrl" value="myurl.conm/auth/GoogleOAuth"/>

它在我的 Apphost 中注册如下:

 Plugins.Add(new AuthFeature(() => new CustomUserSession(),
        new IAuthProvider[] {
            new CredentialsAuthProvider(appSettings), 
            new FacebookAuthProvider(appSettings), 
            new TwitterAuthProvider(appSettings), 
            new BasicAuthProvider(appSettings), 
            new GoogleOAuth2Provider(appSettings),
        }) { HtmlRedirect = null });

现在,当我转到 /auth/GoogleOAuth 时,我被重定向到 google,允许 google 使用我的东西,被重定向回我自己的 /auth/GoogleOAuth,我假设 ServiceStack 将处理我的麻烦,然后我收到以下错误:

Response Status

    Error Code
        WebException
    Message
        The remote server returned an error: (400) Bad Request.
    Stack Trace
        [Authenticate: 05/02/2015 09:30:42]: [REQUEST: {provider:GoogleOAuth,state:{thestate} }] System.Net.WebException: The remote server returned an error: (400) Bad Request. at System.Net.HttpWebRequest.GetResponse() at DotNetOpenAuth.Messaging.StandardWebRequestHandler.GetResponse(HttpWebRequest request, DirectWebRequestOptions options)

我尝试摆弄redirectUrlcallbackUrl,但有些事情告诉我这是另一个问题。我以同样的方式使用 twitter 和 facebook 建立身份验证。

它崩溃的响应网址是这样的:myurl/OpenAuthenticationTest/auth/GoogleOAuth?state={statenumber}&amp;code={areallylongcode

有什么想法吗?

编辑:它似乎在错误之间切换:我有时也会得到这个:

Unexpected OAuth authorization response received with callback and client state that does not match an expected value.

Edit2:我进行了更多测试,结果发现linkedIn 也发生了完全相同的事情,它也是OAuth2。所有oauth1 工作正常。

【问题讨论】:

  • 我将CustomUserSession 更改为AuthUserSession,因为互联网上的某个地方有人建议我的会话不存在,因此我的状态只是随机的。但没有运气。
  • 异常表示远程 OAuth 服务器返回了 400 错误请求。您可以Install Glimpse and with DotNetOpenAuth 记录和诊断任何 DNOA 问题。
  • @mythz 有道理,我试试看,谢谢。
  • 我自己只能使用 Glimpse 调试内部 DNOA 问题。真的看不出这里有什么问题,LinkedIn/GoogleOAuth2 适用于我尝试过的每个应用程序:mvc.servicestack.nethttpbenchmarks.servicestack.net,(源代码链接自Live DemosServiceStack.AuthWeb.Tests。 OAuth 问题通常是由于应用程序配置错误造成的,但在这里无法判断。 Proxies/ReverseProxies 也会破坏 url 并破坏 OAuth。也许在 SS 演示之一中测试您的应用程序配置? MVC demo 显示调试信息。
  • 原来是与与代理相结合的本地主机链接的问题。感谢您抽出宝贵时间

标签: c# oauth servicestack dotnetopenauth


【解决方案1】:

原来是我指的是谷歌和谷歌的网址中的一个问题。我在代理上安装了 IIS,所以我可以从外部访问它,但是谷歌真的不喜欢这样。当我输入 http://localhost 作为我的 URL 时,一切正常。

【讨论】:

    猜你喜欢
    • 2015-05-11
    • 1970-01-01
    • 2015-08-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-02-25
    • 2014-08-19
    相关资源
    最近更新 更多