I’m still trying to figure out what could be wrong in my request. I tried setting the consumer_key, consumer_secret, nonce and timestamp the same as in Implementing Sign in with Twitter, in order to see If I would build the same request.
What could probably be built wrongly in my request was the signature, so I tried checking it first. As said in the authorization from the docs (from before) the signature for the base string + key is:
oauth_signature="F1Li3tvehgcraF8DMJ7OyxO4w9Y%3D
I expected to obtain the same signature, since every parameter were the same, but in fact I obtained this signature:
%2FG%2FPJczMcszvW4G6eVtpMNkzMng%3D
So first I thought my signing algorithm was off, so I tried this HMAC-SHA1 online tool. I inserted my signature base string and my signature key, and the signature for the tool was the same as I’ve obtained, so it’s probably no my signing algorithm.
Since the key is pretty obvious (“key”+"&"), the only thing that could be different from the docs signature could be the signature base string parameters. Now I can’t say, since the docs don’t tell much about what parameters to use.
I’m building the signature as such:
// Parameters from the docs link above
oauth_consumer_key = "cChZNFj6T5R0TigYB9yd1w";
oauth_consumer_secret = "L8qq9PZyRg6ieKGEKhZolGC0vJWLw8iEJ88DRdyOg";
token_secret = "";
nonce = "ea9ec8429b68d6b77cd5600adbbb0456";
timestamp = "1318467427";
HTTP_METHOD = "POST";
signature_method = "HMAC-SHA1";
normalized_url = "https://api.twitter.com/oauth/request_token";
parameters_string = "oauth_consumer_key=" + urlencode(*consumer_key) + "&" +
"oauth_nonce=" + urlencode(*nonce) + "&" +
"oauth_signature_method=" + signature_method +"&" +
"oauth_timestamp=" + timestamp + "&" +
"oauth_version=" + "1.0";
signature_base_string += HTTP_METHOD; // "POST"
signature_base_string += "&";
signature_base_string += urlencode(*normalized_url); // "https://api.twitter.com/oauth/request_token"
signature_base_string += "&";
signature_base_string += urlencode(*parameters_string); // as seen above
signature_key = urlencode(consumer_secret) + "&" + urlencode(token_secret);
// Signing algorithm uses signature_base_string and signature_key to obtain the signature
Am I missing parameters here? Am I url encoding as I should be (assuming url encoding is implemented correctly)?
Thanks!