Continued: Setting up Twitter OAuth without third-party libraries
Thanks to Mr. Nylander, I managed to get my OAuth class (although after a long time)! However, I am confused by several aspects of the oAuth stream.
Here is a breakdown of what happens in the program I did:
== edit, I think I will send a partial code, it is difficult for me to explain only the words for me ==
//1st code segment HttpWebRequest request = (HttpWebRequest)WebRequest.Create("https://api.twitter.com/oauth/request_token"); string response = ""; HttpWebResponse resp = (HttpWebResponse)request.GetResponse(); using (StreamReader reader = new StreamReader(resp.GetResponseStream())) { response = reader.ReadToEnd(); }
Up to this point I can get a response successfully.
Answer → oauth_token = asjndiqufh9uf & oauth_token_secret = oinroiqurhwunwer & oauth_callback_confirmed = true
//2nd code segment Process proc = new Process(); proc.StartInfo.UseShellExecute = true; proc.StartInfo.FileName = "https://api.twitter.com/oauth/authenticate?" + response; proc.Start();
This leads the user (me) to a page where I have to choose whether I want to authorize it or not. If I agree, I will be taken to the PIN page.
//3rd code segment Console.WriteLine("Enter the PIN"); string pin = Console.ReadLine(); baseString = generateBaseString("POST", "https://api.twitter.com/oauth/access_token", oauth_token); oauth_signature = generateSignature(baseString, oauth_token_secret); HttpWebRequest request2 = (HttpWebRequest)WebRequest.Create("https://api.twitter.com/oauth/access_token"); request2.Method = "POST"; request2.Headers["Authorization"] = generateAuthorizationHeader(oauth_token); string response2 = ""; HttpWebResponse resp2 = (HttpWebResponse)request2.GetResponse(); using (StreamReader reader = new StreamReader(resp2.GetResponseStream())) { response2 = reader.ReadToEnd(); } Console.WriteLine(response2); }
In the code, it simply asks for the PIN to be entered into the application, and then the final oauth_token and oauth_token_secret file is returned in response2 for the fully working oAuth application. (tl; dr - at the moment the application already has ALL the toners he needs)
-If I NOT logged in during the second code segment, regardless of whether I find the PIN code or not, I get a 401 Unauthorized error, I assume this is expected.
-If I logged in in the second segment of the code and was redirected to the PIN page, but then did NOT choose NOT to enter the PIN code or enter the wrong PIN code in my application, I still get successful authentication and can get the final one without any either problems. What for?
-Am, am I doing 3-legged oAuth or OOB oAuth?
Why do I need a PIN?
-How should I use the PIN correctly (if I need it)?
-How should I authenticate without a PIN (if I do not need it)?
-How can I make sure that users do not always see the PIN page after authentication once? I can put the callback in the very first request, but what if I don't want the user to be redirected to any page at all?