How to use RestSharp with OAuth?

Sergey Aldoukhov picture Sergey Aldoukhov · May 31, 2011 · Viewed 18.8k times · Source

I am confused which factory OAuth1Authenticator factory method should I use. I think I should get a consumer secret token (can I get it with RestSharp?), then use OAuth1Authenticator.ForRequestToken, then obtain access token and secret access token(how?), then use OAuth1Authenticator.ForAccessToken and use the return value from this point forward.

But it seems that RestSharp is architectured to use the only one authenticator and I can't seem to find a way from a cold start (having only app token) to having all the necessary credentials (consumer key and secret, access key and secret).

Bonus questions:

  1. What .ForClientAuthentication and .ForProtectedResource methods are for?
  2. Why OAuth2Authenticatior is in a different namespace from OAuth1Authenticator?

Answer

John Sheehan picture John Sheehan · Jun 1, 2011

OAuth 1 is multi-step, so you have to use a different static method each step of the way. There's an example here: https://github.com/restsharp/RestSharp/blob/master/test/RestSharp.IntegrationTests/OAuth1Tests.cs