servicestack,dotnetopenauth,C#,Oauth,servicestack,Dotnetopenauth" /> servicestack,dotnetopenauth,C#,Oauth,servicestack,Dotnetopenauth" />

C# 来自Google的Oauth2响应给出了DotNetOpenAuth 400错误请求

C# 来自Google的Oauth2响应给出了DotNetOpenAuth 400错误请求,c#,oauth,servicestack,dotnetopenauth,C#,Oauth,servicestack,Dotnetopenauth,我正在用谷歌的ServiceStack设置OAuth2。我在我的web.config中注册了google,如下所示: <add key="oauth.GoogleOAuth.ConsumerKey" value="key"/> <add key="oauth.GoogleOAuth.ConsumerSecret" value="secretkey"/> <add key="oauth.GoogleOAuth.RedirectUrl"

我正在用谷歌的ServiceStack设置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"/>
 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)
我试着摆弄
重定向URL
回调URL
,但有消息告诉我这是另一个问题。我用twitter和facebook以同样的方式建立身份验证

它崩溃的响应url如下:
myurl/OpenAuthenticationTest/auth/GoogleOAuth?state={statenumber}&code={areallylongcode

有什么想法吗

编辑:它似乎在错误之间切换:我有时也会遇到这种情况:

收到意外的OAuth授权响应,回调和客户端状态与预期值不匹配。


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

这是url中的一个问题,我指的是谷歌和谷歌。我把我的IIS放在一个代理上,这样我就可以从外部访问它了,但谷歌真的没有当我输入
http://localhost
由于我的URL一切正常。

我将
CustomUserSession
更改为
AuthUserSession
,因为在internet上的某个地方,有人建议我的会话不存在,因此我的状态只是随机的。但没有运气。例外情况是远程OAuth server返回了一个400错误的请求。您可以记录和诊断任何DNOA问题。@mythz很有意义,我会尝试一下,谢谢。我只能用Gliesh自己调试内部DNOA问题。我真的看不出这里有什么问题,LinkedIn/GoogleOAuth2可以与我尝试过的每个应用一起工作:,(源代码链接自).OAuth问题通常是由于配置错误的应用程序造成的,但在此处无法确定。代理/反向代理也会损坏URL并破坏OAuth。也许可以在其中一个SS演示中测试您的应用程序配置?显示调试信息。结果是与本地主机和代理的链接有关的问题。感谢您花费时间