Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
568 views
in Technique[技术] by (71.8m points)

oauth - Asp.Net MVC 5 Owin Twitter Auth throwing 401 Exception

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.

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:

Response status code does not indicate success: 401 (Unauthorized).

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();

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:

Stack Trace

Any ideas?

question from:https://stackoverflow.com/questions/21651211/asp-net-mvc-5-owin-twitter-auth-throwing-401-exception

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.

  1. https://apps.twitter.com/
  2. Go to the Settings Tab
  3. Set a CallBack URL to any website. Even if it is not real.

This should solve you problem.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...