【发布时间】: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)
我尝试摆弄redirectUrl 和callbackUrl,但有些事情告诉我这是另一个问题。我以同样的方式使用 twitter 和 facebook 建立身份验证。
它崩溃的响应网址是这样的:myurl/OpenAuthenticationTest/auth/GoogleOAuth?state={statenumber}&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.net,httpbenchmarks.servicestack.net,(源代码链接自Live Demos)ServiceStack.AuthWeb.Tests。 OAuth 问题通常是由于应用程序配置错误造成的,但在这里无法判断。 Proxies/ReverseProxies 也会破坏 url 并破坏 OAuth。也许在 SS 演示之一中测试您的应用程序配置? MVC demo 显示调试信息。
-
原来是与与代理相结合的本地主机链接的问题。感谢您抽出宝贵时间
标签: c# oauth servicestack dotnetopenauth