Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is Twitter implemeting OAuth off spec? (C#)

Tags:

c#

oauth

twitter

I've been battling with OAuth and Twitter for 2 weeks now trying to implement it. After many rewrites of my code I've finally got a library which performs the request as it should be based on the 1.0 spec. I've verified it by using this verifier on Google Code, and this verifier from Hueniverse.

My version, the Google version and the Hueniverse version all produce the exact same signature, so I've concluded that I am no longer the cause (but I could be putting a foot in my mouth by stating this...).

I test my implementation by first creating a test request using Twitter's API Console, in this case a status update. I copy the params that change, the oauth_nonce and oauth_timestamp, into all three signers stated above. All other params are always the same, tokens/secrets/etc.

Twitter's console produces one signature, but the other three above all produce a different signature (from Twitter's, identical to each other).

So, my question is, why am I getting this:

<?xml version="1.0" encoding="UTF-8"?>
<hash>
    <request>/1/statuses/update.xml</request>
    <error>Could not authenticate with OAuth.</error>
</hash>

...when I should be implementing the spec to the "T"?

Is there something specific that Twitter needs/wants as part of the request? I've counted the nonce generated by Twitter as 42 chars long, is that correct? Should it be 42 chars long?

I would appreciate help from anyone with more insight into the API than I obviously have...

Thanks in advance!

UPDATE: Someone asked about how I send the authentication params, but has since deleted their post, idk why. Anyway, the authorization params are sent via the Authorization header.

UPDATE/SOLUTION: Is moved down to the bottom where it belongs as an answer.

like image 723
Gup3rSuR4c Avatar asked Nov 05 '22 11:11

Gup3rSuR4c


1 Answers

The only problem I had when implementing the OAuth specification with Twitter as the main target was, that Twitter has restricted the nonce to only accept ASCII characters (while the specification actually allows any bytes). Therefor I changed my implementation to generate a random int (with 60 bits, so longer than 42 chars) instead.

Other than that, Twitter's implementation seems to be completely correct; at least I didn't have any issues.

I suggest you to use some of the many OAuth sandboxes around (for example this or this) to really check if everything goes right and for example if you include everything necessary into the signature etc..

like image 130
poke Avatar answered Nov 14 '22 22:11

poke