diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/oauth2.c | 26 | ||||
-rw-r--r-- | lib/oauth2.h | 9 |
2 files changed, 9 insertions, 26 deletions
diff --git a/lib/oauth2.c b/lib/oauth2.c index 7cb28105..93891317 100644 --- a/lib/oauth2.c +++ b/lib/oauth2.c @@ -27,27 +27,10 @@ #include "oauth.h" #include "url.h" -struct oauth2_service oauth2_service_google = -{ - "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", - "6C-Zgf7Tr7gEQTPlBhMUgo7R", -}; -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 ) +char *oauth2_url( const struct oauth2_service *sp ) { return g_strconcat( sp->auth_url, - "?scope=", scope, + "?scope=", sp->scope, "&response_type=code" "&redirect_uri=", sp->redirect_url, "&client_id=", sp->consumer_key, @@ -120,10 +103,15 @@ static void oauth2_access_token_done( struct http_request *req ) struct oauth2_access_token_data *cb_data = req->data; char *atoken = NULL, *rtoken = NULL; + if( getenv( "BITLBEE_DEBUG" ) && req->reply_body ) + printf( "%s\n", req->reply_body ); + if( req->status_code == 200 ) { atoken = oauth2_json_dumb_get( req->reply_body, "access_token" ); rtoken = oauth2_json_dumb_get( req->reply_body, "refresh_token" ); + if( getenv( "BITLBEE_DEBUG" ) ) + printf( "Extracted atoken=%s rtoken=%s\n", atoken, rtoken ); } cb_data->func( cb_data->data, atoken, rtoken ); g_free( atoken ); diff --git a/lib/oauth2.h b/lib/oauth2.h index 6f56b426..c8d18963 100644 --- a/lib/oauth2.h +++ b/lib/oauth2.h @@ -31,22 +31,17 @@ struct oauth2_service char *auth_url; char *token_url; char *redirect_url; + char *scope; char *consumer_key; char *consumer_secret; }; -/* Currently suitable for authenticating to Google Talk only, and only for - 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" /* Generate a URL the user should open in his/her browser to get an authorization code. */ -char *oauth2_url( const struct oauth2_service *sp, const char *scope ); +char *oauth2_url( const struct oauth2_service *sp ); /* Exchanges an auth code or refresh token for an access token. auth_type is one of the two OAUTH2_AUTH_.. constants above. */ |