We are consuming an API which supports OAuth 2 legged authentication. I'm getting this error below when trying to run my rest sharp client OAuth1Authenticator implemenation:
Message: HTTP Status 401 - Invalid signature for signature method HMAC-SHA1
Description: This request requires HTTP authentication (Invalid signature for signature method HMAC-SHA1).
Here's the code snippet:
var restClient = new RestClient(baseUrl);
restClient.Authenticator =
OAuth1Authenticator.ForProtectedResource(ConfigurationManager.AppSettings["ConsumerKey"],
ConfigurationManager.AppSettings["ConsumerSecret"], string.Empty, string.Empty);
var request = new RestRequest(relativePath);
request.AddParameter(new Parameter { Name = "username", Value = username, Type = ParameterType.QueryString });
request.AddParameter(new Parameter { Name = "firstname", Value = firstname, Type = ParameterType.QueryString });
request.AddParameter(new Parameter { Name = "surname", Value = surname, Type = ParameterType.QueryString });
request.AddParameter(new Parameter { Name = "email", Value = email, Type = ParameterType.QueryString });
request.AddParameter(new Parameter { Name = "password", Value = password, Type = ParameterType.QueryString });
request.Resource = string.Format(relativePath);
request.Method = Method.POST;
var response = restClient.Execute<object>(request);
It appears to me that we need to pass the signature with request. But just haven't figured out how to pass this using RestSharp.
Could someone point me to right direction?
UPDATE
Interestingly when I used custom OAuthBase class below for signing the request. It works well. http://oauth.googlecode.com/svn/code/csharp/OAuthBase.cs
I really would like to use RestSharp without writing any custom code. Not sure what exactly am I doing wrong.