tags:

views:

378

answers:

4

How many characters long can an oauth access token and oauth access secret be and what are the allowed characters? I need to store them in a database.

+1  A: 

I am not sure there are any explicit limits. The spec doesn't have any. That said, OAuth tokens are often passed as url parameters and so have some of the same limitations. ie need to be properly encoded, etc.

BaroqueBobcat
A: 

An OAuth token is conceptually an arbitrary-sized sequence of bytes, not characters. In URLs, it gets encoded using standard URL escaping mechanisms:

  unreserved = ALPHA, DIGIT, '-', '.', '_', '~'

Everything not unreserved gets %-encoded.

I'm not sure whether you just talk about the oauth_token parameter that gets passed around. Usually, additional parameters need to be stored and transmitted as well, such as oauth_token_secret, oauth_signature, etc. Some of them have different data types, for example, oauth_timestamp is an integer representing seconds since 1970 (encoded in decimal ASCII digits).

Martin v. Löwis
+1  A: 

OAuth doesn't specify the format or content of a token. We simply use encrypted name-value pairs as token. You can use any characters in token but it's much easier to handle if the token is URL-safe. We achieve this by encoding the ciphertext with an URL-safe Base64.

ZZ Coder
A: 

As most people already pointed out. The OAuth specification doesn't give you exact directions but they do say...

cited from: http://tools.ietf.org/html/draft-hammer-oauth-10#section-4.9

"Servers should be careful to assign shared-secrets which are long enough, and random enough, to resist such attacks for at least the length of time that the shared-secrets are valid."

"Of course, servers are urged to err on the side of caution, and use the longest secrets reasonable."

on the other hand, you should consider the maximum URL length of browsers:

see: [http://www.boutell.com/newfaq/misc/urllength.html][1]

PK