Asp.Net MVC 5 Owin Twitter Auth 抛出 401 异常
我使用 Owin 中间件设置了 OAuth 身份验证,基于使用个人帐户"身份验证启动新 Web 项目时创建的默认项目.
I have set up OAuth authentication using the Owin middleware based off the default project that gets created when starting a new Web project using "Individual accounts" authentication.
我对其进行了一些调整,但 Facebook 和 Google 运行良好,但是,当我单击twitter"按钮发出挑战时,它会抛出 500 http 异常并显示错误消息:
I've tweaked it a bit, but Facebook and Google are working great, however, when I click on the "twitter" button to issue the challenge, it's throwing a 500 http exception with the error message:
响应状态码不表示成功:401(未授权).
Response status code does not indicate success: 401 (Unauthorized).
这只出现在 Twitter 上.这是我的身份验证配置:
This only comes up with Twitter. Here is my auth config:
// Just a configuration section that reads from the web.config
var configuration = new OwinCookieConfigurationSection("owinCookieConfiguration");
app.UseCookieAuthentication(GetCookieAuthenticationOptions(configuration));
app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie);
app.UseTwitterAuthentication(
consumerKey: "XXX",
consumerSecret: "XXX"
);
app.UseFacebookAuthentication(
appId: "XXX",
appSecret: "XXX"
);
app.UseGoogleAuthentication();
这绝对是一个 500 错误,而不是它所指示的 401 错误,我已经确认它从未使它通过原始帖子挑战到 Twitter.堆栈跟踪似乎显示 Twitter 没有从获取请求令牌调用返回成功代码:
It's definitely a 500 error, not a 401 error as it indicates and I have confirmed it never makes it passed the original post challenge to Twitter. The stack trace appears to show Twitter is not returning a success code from the ObtainRequestToken call:
有什么想法吗?
您需要进入 Twitter Dev App 并添加一个网站地址.我知道这看起来很傻,但这会解决您的问题.
You need to go into the Twitter Dev App and add a website address. I know it seem silly but this will solve your problem.
- https://apps.twitter.com/
- 转到设置"标签
- 为任何网站设置回调 URL.即使它不是真的.
这应该可以解决您的问题.
This should solve you problem.