OAuth library works nicely for XAuth

Apr 19, 2011 at 6:33 AM

Hi all,

Just got the OAuth library to work with twitter XAuth; pretty happy it works so I thought I'd share it here.  Here's the code fragment I'm using:

string username =  "~~~username~~~";
string password = "~~~password~~~";
string CONSUMER_KEY = "~~~consumer key~~~";
string CONSUMER_SECRET = "~~~consumer secret~~~";

Manager man = new Manager(CONSUMER_KEY, CONSUMER_SECRET, "", "");
string url = "https://api.twitter.com/oauth/access_token?x_auth_username="+username+"&x_auth_password="+password+"&x_auth_mode=client_auth";
string header = man.GenerateAuthzHeader(url, "POST");

var request = (HttpWebRequest)WebRequest.Create(url);

request.Method = "POST";
request.PreAuthenticate = true;
request.AllowWriteStreamBuffering = true;
request.Headers.Add("Authorization", header);

using (var updateResponse = (HttpWebResponse)request.GetResponse())
 	Stream receiveStream = updateResponse.GetResponseStream ();
	StreamReader readStream = new StreamReader (receiveStream, Encoding.UTF8);

	Console.WriteLine (readStream.ReadToEnd ());

Cheers all,

Apr 20, 2011 at 6:03 PM
Edited Apr 20, 2011 at 6:09 PM

Sweet!  Thanks for the post, Russ. 

Hey, did you have to modify the code of the Manager class? 

Apr 20, 2011 at 8:45 PM

No modificiation at all.  The documentation says:

xAuth requires that you use header-based OAuth authentication against an SSL access token end point, using the POST HTTP method.

Which made me think I'll need to pass the parameters in the POST body, but it appears to be happy with the parameters passed in the querystring of a POST.