diff options
author | Wilmer van der Gaast <wilmer@gaast.net> | 2011-03-27 15:09:55 +0100 |
---|---|---|
committer | Wilmer van der Gaast <wilmer@gaast.net> | 2011-03-27 15:09:55 +0100 |
commit | ce617f0a445df1201808a9cd29722a9cf6c96b95 (patch) | |
tree | 6ac7212932eca89a84bb311345c40149f7a2dde1 | |
parent | ff9456329255ef8b227f9322ca8d25ef6c790e7e (diff) |
Tweaks to allow authenticating to identi.ca with OAuth. Doesn't seem to work
completely for whatever the reason may be (invalid signature). I give up for
now. Stuff does actually work if you generate access tokens using different
software so BitlBee's definitely able to generate good signatures.
-rw-r--r-- | lib/oauth.c | 8 | ||||
-rw-r--r-- | protocols/twitter/twitter.c | 26 |
2 files changed, 30 insertions, 4 deletions
diff --git a/lib/oauth.c b/lib/oauth.c index 14e7797c..9c67363a 100644 --- a/lib/oauth.c +++ b/lib/oauth.c @@ -107,10 +107,14 @@ static char *oauth_sign( const char *method, const char *url, static char *oauth_nonce() { - unsigned char bytes[9]; + unsigned char bytes[21]; + char *ret = g_new0( char, sizeof( bytes) / 3 * 4 + 1 ); random_bytes( bytes, sizeof( bytes ) ); - return base64_encode( bytes, sizeof( bytes ) ); + base64_encode_real( bytes, sizeof( bytes), (unsigned char*) ret, "0123456789" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0A" ); + + return ret; } void oauth_params_add( GSList **params, const char *key, const char *value ) diff --git a/protocols/twitter/twitter.c b/protocols/twitter/twitter.c index dbe9b984..63f648df 100644 --- a/protocols/twitter/twitter.c +++ b/protocols/twitter/twitter.c @@ -98,15 +98,37 @@ static const struct oauth_service twitter_oauth = .consumer_secret = "FCxqcr0pXKzsF9ajmP57S3VQ8V6Drk4o2QYtqMcOszo", }; +static const struct oauth_service identica_oauth = +{ + "http://identi.ca/api/oauth/request_token", + "http://identi.ca/api/oauth/access_token", + "https://identi.ca/api/oauth/authorize", + .consumer_key = "e147ff789fcbd8a5a07963afbb43f9da", + .consumer_secret = "c596267f277457ec0ce1ab7bb788d828", +}; + static gboolean twitter_oauth_callback( struct oauth_info *info ); +static const struct oauth_service *get_oauth_service( struct im_connection *ic ) +{ + struct twitter_data *td = ic->proto_data; + + if( strstr( td->url_host, "identi.ca" ) ) + return &identica_oauth; + else + return &twitter_oauth; + + /* Could add more services, or allow configuring your own base URL + + API keys. */ +} + static void twitter_oauth_start( struct im_connection *ic ) { struct twitter_data *td = ic->proto_data; imcb_log( ic, "Requesting OAuth request token" ); - td->oauth_info = oauth_request_token( &twitter_oauth, twitter_oauth_callback, ic ); + td->oauth_info = oauth_request_token( get_oauth_service( ic ), twitter_oauth_callback, ic ); /* We need help from the user to complete OAuth login, so don't time out on this login. */ @@ -262,7 +284,7 @@ static void twitter_login( account_t *acc ) td->user = acc->user; if( strstr( acc->pass, "oauth_token=" ) ) - td->oauth_info = oauth_from_string( acc->pass, &twitter_oauth ); + td->oauth_info = oauth_from_string( acc->pass, get_oauth_service( ic ) ); sprintf( name, "%s_%s", td->prefix, acc->user ); imcb_add_buddy( ic, name, NULL ); |