Basic Authentication

1,298 views
Skip to first unread message

Bear

unread,
Jun 15, 2011, 6:07:52 PM6/15/11
to RestSharp
Hi,

I've been playing with RestSharp and so far, it seems pretty awesome.

I've managed to get a simple example running for just pulling my own
statuses from twitter.

var statuses = new List<Status>();

const string consumerKey = "...";
const string consumerSecret = "...";

const string accessKey = "...";
const string accessSecret = "...";

var baseUrl = "http://api.twitter.com";

var client = new RestClient(baseUrl);

client.Authenticator =
OAuth1Authenticator.ForProtectedResource(
consumerKey, consumerSecret, accessKey, accessSecret
);

var request = new RestRequest("/1/statuses/
user_timeline.json", Method.GET);
var response = client.Execute<List<Status>>(request);

if ( response != null )
{
statuses = response.Data;
}

return statuses;

This works great.

My aim is to create single web app (MVC3) that pulls in data from my
own accounts using the APIs at Twitter, Soundcloud and Flickr
(possibly a few others). Is there a simple way of accessing the APIs
Soundcloud and Flickr using RestSharp without having to do the "oAuth
Dance"? I'm not making an app that will be used by others, it'll be
basically read-only of my statuses, comments, photos etc. I just want
to login silently as me on my server and use the apis.

Am I overlooking something here? I'm aware of the twitter // netflix
examples in the unit tests. However both of these, require a
breakpoint to grab the verification key. Ideally I want to avoid
this.

Thanks in advance




John Sheehan

unread,
Jun 15, 2011, 7:24:49 PM6/15/11
to rest...@googlegroups.com
It's up to each API to implement authentication however they want.
Most don't use OAuth. If you need to use Basic auth you do this:

var client = new RestClient();
client.Authenticator = new HttpBasicAuthenticator("username", "password");

Some APIs will use keys, others won't. You just need to use whatever
combination of Authenticators and AddParameter calls needed to meet
the API requirements.

Bear

unread,
Jun 16, 2011, 10:46:24 AM6/16/11
to RestSharp
Thanks for the reply.

I've been trying to get my head around oAuth and think I get it now.
It makes total sense to have some form of user interaction for each
authorisation.
Further experimentation of RestSharp and stuff like flickr means it's
easy to call and consume public api methods that don't require any
authentication, e.g. flickr.people.getPublicPhotos.

Extremely impressed with this library. It's a keeper for sure. :-)

Thanks for your hard work with this.
Reply all
Reply to author
Forward
Message has been deleted
0 new messages