I’ve spent days looking into this and I’m no further on. I’m trying to allow users to log in to my .Net (MVC) website using Twitter. It used to work, but at some point it stopped working on my production webserver (I’ve removed patches since I noticed it stopped working, but it still doesn’t work).
The problem is the initial API call to https://api.twitter.com/oauth/request_token. On my localhost Windows 10 dev machine it works fine and it returns: oauth_token=xxx&oauth_token_secret=xxx&oauth_callback_confirmed=true
But on the webserver it returns a page of a poodle sat on a chair with an error 404!
I get the same issue with any library I use (TweetSharp, TweetInv, Microsoft.Owin.Security.Twitter and even a manual HttpWebRequest!) so it isn’t related to that.
It WORKS on my localhost (Visual Studio 2022). It WORKS using Postman on my local machine AND on my web server.
It does NOT work on my web server (Server 2012 R2) via my website.
Because the libraries didn’t work, I made a working Localhost example using HttpWebRequest so i could play around with headers etc to reflect Postman/Fiddler.
ServicePointManager.Expect100Continue = true;
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
HttpWebRequest request = (HttpWebRequest)WebRequest.Create("https://api.twitter.com/oauth/request_token");
request.Method = "POST";
request.Headers["Authorization"] = OAuthHeader;
request.Accept = "*/*";
request.ContentType = "application/x-www-form-urlencoded";
request.KeepAlive = true;
request.AutomaticDecompression = (DecompressionMethods.GZip | DecompressionMethods.Deflate);
Again, it worked locally but not on my web server.
My MVC site uses .net 4.8 (targetFramework="4.8").
I have added the URLs (localhost IP and my live domain callback URL) to my callback settings in the app settings.
I am using Oauth1.0a with read only permissions.
I’ve used IISCrypto to verify TLS1.2 is enabled, and it looks ok.
I’m running out of ideas!! Has anyone got any pointers? Thanks!
UPDATE
I’ve run a simple CURL command as per below, and get the following:
2
Answers
I've finally got it working after days of debugging. It has something to do with Schannel/TLS/Cipher suites, but I'm not exactly sure what the specific fix was: https://www.alkanesolutions.co.uk/2022/06/07/twitter-api-giving-http-404-not-found-when-requesting-a-token/
try checking with curl command like below from your server machine
You need to ensure you are using TLS1.2 when you make calls to api.twitter.com – Twitter no longer supports the old TLS v1
If you get TLS issue try updating the Powershell on server machine to always use TLS1.2 by executing the command below:
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
I got the expected response instead of the 404 error.
that error went away and then make sure
from your code base you are ensuring it to use TLS1.2
for me these lines were causing issue , so I remove them which I added back in 2019 to fix TLS issue itself