-1

I'm making a service request(POST) with curl and OAuth signature.

I have created a signature with the following code:

$signature_method = new OAuthSignatureMethod_HMAC(strtolower('SHA1'));  

$consumer = new DrupalOAuthConsumer($consumer_credentials['c_key'], $consumer_credentials['c_secret'], array());

$request = DrupalOAuthRequest::from_consumer_and_token($consumer, NULL, $options[$op]['method'], $options[$op]['url'], NULL);  

$request->sign_request($signature_method, $consumer, null);

And added to the curl header the OAuth credentials. The problem is that when on the server side the signatures don't match. For example on the server:

rsXZTiGBRYU+8WjxfnxZQ1g3IPA=

and client:

rsXZTiGBRYU 8WjxfnxZQ1g3IPA=

and because of this it's giving me an "Invalid signature" error. I think it's related to some encoding but can't figure it out.

Anybody has any ideas as to what should I do?

1 Answer 1

0

The solution to my problem was the way i was sending the signature in the header of the curl method:

$oauth_signature = $request->get_parameter('oauth_signature');

$header = array('Authorization: OAuth '
    . 'oauth_consumer_key="' . $consumer_credentials['c_key'] . '", '
    . 'oauth_nonce="' . $oauth_nonce . '", '
    . 'oauth_signature="' . urlencode($oauth_signature) . '", '
    . 'oauth_signature_method="HMAC-SHA1", '
    . 'oauth_timestamp="' . $oauth_timestamp . '", '
    . 'oauth_version="1.0"');

I had to urlencode the signature before sending it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.