2

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.

Nil Pun
  • 17,035
  • 39
  • 172
  • 294
  • This looks intersting https://www.drupal.org/node/1991416 Its drupal but gist is that signatures don't match because the server and the client are using different hashing mechanisms – bumble_bee_tuna Apr 05 '15 at 03:15
  • Had a look at your link but I could not relate this resharp problem. Thanks. – Nil Pun Apr 05 '15 at 03:30
  • Did you look at the first comment ? The gist was to check that the signature of the server and the client is using the same – bumble_bee_tuna Apr 05 '15 at 03:32
  • Problem here is i'm not able to send the signature. I only have consumer key and secret key. Not sure how to pass signature using RestSharp – Nil Pun Apr 05 '15 at 03:36
  • Does this link help? http://stackoverflow.com/questions/26954935/etsy-oauth-authentication-c-sharp-restsharp – Ripu Daman Apr 05 '15 at 12:34
  • It's a 2 legged oauth implementation. See my update please. – Nil Pun Apr 06 '15 at 10:53

1 Answers1

-2

You are passing in empty strings for your access token and access token secret.

restClient.Authenticator =
            OAuth1Authenticator.ForProtectedResource(ConfigurationManager.AppSettings["ConsumerKey"],
                ConfigurationManager.AppSettings["ConsumerSecret"], string.Empty, string.Empty);

Looking at a RestSharp test example it is making sure that the values are provided. Try using that site as a template and see if populating those values helps.

Brian from state farm
  • 2,825
  • 12
  • 17
  • Our provider doesn't provide those extra parameters. Per my last update the OAuthBase.cs works with passing empty values for the other two methods. – Nil Pun Apr 08 '15 at 01:33