aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lib/oauth.c8
-rw-r--r--protocols/twitter/twitter.c26
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 );