diff options
author | Wilmer van der Gaast <wilmer@gaast.net> | 2011-07-31 15:55:00 +0100 |
---|---|---|
committer | Wilmer van der Gaast <wilmer@gaast.net> | 2011-07-31 15:55:00 +0100 |
commit | 39a939ce4ef6717d65c36c97e6a7adf05b125cad (patch) | |
tree | 0522ac97b078445177a02fa581134d8203f6fa33 /lib | |
parent | aa9f1acec3f941cbb6b9fa716db1e775e88005c2 (diff) |
oauth2 changes to address http://twitter.com/Wilmer/status/96715400124968960
Diffstat (limited to 'lib')
-rw-r--r-- | lib/oauth2.c | 24 | ||||
-rw-r--r-- | lib/oauth2.h | 6 |
2 files changed, 22 insertions, 8 deletions
diff --git a/lib/oauth2.c b/lib/oauth2.c index d9eefa9f..a54ef431 100644 --- a/lib/oauth2.c +++ b/lib/oauth2.c @@ -29,17 +29,27 @@ struct oauth2_service oauth2_service_google = { - "https://accounts.google.com/o/oauth2/", + "https://accounts.google.com/o/oauth2/auth", + "https://accounts.google.com/o/oauth2/token", + "urn:ietf:wg:oauth:2.0:oob", "783993391592.apps.googleusercontent.com", "k5_EV4EQ7jEVCEk3WBwEFfuW", }; +struct oauth2_service oauth2_service_facebook = +{ + "https://www.facebook.com/dialog/oauth", + "https://graph.facebook.com/oauth/access_token", + "http://www.bitlbee.org/main.php/fb.html", + "126828914005625", + "4b100f0f244d620bf3f15f8b217d4c32", +}; char *oauth2_url( const struct oauth2_service *sp, const char *scope ) { - return g_strconcat( sp->base_url, "auth" + return g_strconcat( sp->auth_url, "?scope=", scope, "&response_type=code" - "&redirect_uri=urn:ietf:wg:oauth:2.0:oob", + "&redirect_uri=", sp->redirect_url, "&client_id=", sp->consumer_key, NULL ); } @@ -63,7 +73,7 @@ int oauth2_access_token( const struct oauth2_service *sp, struct http_request *req; struct oauth2_access_token_data *cb_data; - if( !url_set( &url_p, sp->base_url ) ) + if( !url_set( &url_p, sp->token_url ) ) return 0; oauth_params_add( &args, "client_id", sp->consumer_key ); @@ -71,7 +81,7 @@ int oauth2_access_token( const struct oauth2_service *sp, oauth_params_add( &args, "grant_type", auth_type ); if( strcmp( auth_type, OAUTH2_AUTH_CODE ) == 0 ) { - oauth_params_add( &args, "redirect_uri", "urn:ietf:wg:oauth:2.0:oob" ); + oauth_params_add( &args, "redirect_uri", sp->redirect_url ); oauth_params_add( &args, "code", auth ); } else @@ -81,13 +91,13 @@ int oauth2_access_token( const struct oauth2_service *sp, args_s = oauth_params_string( args ); oauth_params_free( &args ); - s = g_strdup_printf( "POST %s%s HTTP/1.0\r\n" + s = g_strdup_printf( "POST %s HTTP/1.0\r\n" "Host: %s\r\n" "Content-Type: application/x-www-form-urlencoded\r\n" "Content-Length: %zd\r\n" "Connection: close\r\n" "\r\n" - "%s", url_p.file, "token", url_p.host, strlen( args_s ), args_s ); + "%s", url_p.file, url_p.host, strlen( args_s ), args_s ); g_free( args_s ); cb_data = g_new0( struct oauth2_access_token_data, 1 ); diff --git a/lib/oauth2.h b/lib/oauth2.h index 657a0ab3..6f56b426 100644 --- a/lib/oauth2.h +++ b/lib/oauth2.h @@ -28,7 +28,9 @@ typedef void (*oauth2_token_callback)( gpointer data, const char *atoken, const struct oauth2_service { - char *base_url; + char *auth_url; + char *token_url; + char *redirect_url; char *consumer_key; char *consumer_secret; }; @@ -37,6 +39,8 @@ struct oauth2_service accounts that have 2-factor authorization enabled. */ extern struct oauth2_service oauth2_service_google; +extern struct oauth2_service oauth2_service_facebook; + #define OAUTH2_AUTH_CODE "authorization_code" #define OAUTH2_AUTH_REFRESH "refresh_token" |