1st. step, getting url to verify, and verifier is ok.
Using the same method that in the request_token to sign the request, I get "unauthorized", "oauth_problem = signature invalid".
I verify the code letter by letter, and I can't find the problem.
- step, request token -> OK
- Get verifier code in the url -> OK
- Generating the access_token, signature invalid.
I had serveral functions, but I put the code readable in a single function to find the problem:
public void GetAccessToken(string oauthVerifier)
{
IRestResponse response;
RestClient client = new RestClient(apiURI);
string timeStamp = DateTimeOffset.UtcNow.ToUnixTimeSeconds().ToString();
string atNonce = Guid.NewGuid().ToString();
RestRequest request = new RestRequest(GET_ACCESS_TOKEN_URL, Method.GET);
request.AddParameter("oauth_consumer_key", consumerKey);
request.AddParameter("oauth_timestamp", timeStamp);
request.AddParameter("oauth_nonce", atNonce);
request.AddParameter("oauth_signature_method", SIGNATURE_METHOD);
request.AddParameter("oauth_signature", "");
request.AddParameter("oauth_token", token);
request.AddParameter("oauth_verifier", oauthVerifier);
//var parameters = new SortedDictionary<string, string>();
var parameters = new SortedDictionary<string, string>
{
{"oauth_consumer_key", consumerKey},
{"oauth_timestamp", timeStamp},
{"oauth_nonce", atNonce},
{"oauth_signature_method", SIGNATURE_METHOD},
{ "oauth_token", token },
{ "oauth_verifier", oauthVerifier }
};
var sb = new StringBuilder();
sb.Append("GET");
sb.Append("&" + WebUtility.UrlEncode(apiURI + GET_ACCESS_TOKEN_URL));
sb.Append("&" + WebUtility.UrlEncode(NormalizeParameters(parameters)));
var signatureBase = sb.ToString();
var signatureKey = string.Format("{0}&{1}", WebUtility.UrlEncode(consumerSecret), WebUtility.UrlEncode(tokenSecret));
var hmac = new HMACSHA1(Encoding.ASCII.GetBytes(signatureKey));
string signature = Convert.ToBase64String(hmac.ComputeHash(Encoding.ASCII.GetBytes(signatureBase)));
request.Parameters[4].Value = signature;
response = client.Execute(request);
}
The response variable get "unauthorized" because the "signature_invalid".
Any help is welcome, thank you in advance!
Update 1
Oauth documentation says that the signature have to be urlencoded too, then I after convert it to base 64 string, I urlencode it too:
request.Parameters[4].Value = WebUtility.UrlEncode(signature);
Whatever, still returning "signature invalid".
Some light from the sky there? Thank you!