diff options
author | Wilmer van der Gaast <wilmer@gaast.net> | 2011-12-19 01:17:38 +0100 |
---|---|---|
committer | Wilmer van der Gaast <wilmer@gaast.net> | 2011-12-19 01:17:38 +0100 |
commit | bf57cd1bf1019decd67d7c835060675e6a030cde (patch) | |
tree | 878df338abb542a3fa96a76a34b613b40aa99e49 /lib/oauth2.c | |
parent | 9b0ad7e8334c7c01e8d9652aa3b1aaa6c5f6d211 (diff) |
Facebook OAuth2 should now be fully usable.
Diffstat (limited to 'lib/oauth2.c')
-rw-r--r-- | lib/oauth2.c | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/lib/oauth2.c b/lib/oauth2.c index 93891317..4a9d256c 100644 --- a/lib/oauth2.c +++ b/lib/oauth2.c @@ -102,17 +102,33 @@ static void oauth2_access_token_done( struct http_request *req ) { struct oauth2_access_token_data *cb_data = req->data; char *atoken = NULL, *rtoken = NULL; + const char *content_type; if( getenv( "BITLBEE_DEBUG" ) && req->reply_body ) printf( "%s\n", req->reply_body ); - if( req->status_code == 200 ) + content_type = get_rfc822_header( req->reply_headers, "Content-Type", 0 ); + + if( req->status_code != 200 ) + { + } + else if( strstr( content_type, "application/json" ) ) { 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 ); } + else + { + /* Facebook use their own odd format here, seems to be URL-encoded. */ + GSList *p_in = NULL; + + oauth_params_parse( &p_in, req->reply_body ); + atoken = g_strdup( oauth_params_get( &p_in, "access_token" ) ); + rtoken = g_strdup( oauth_params_get( &p_in, "refresh_token" ) ); + oauth_params_free( &p_in ); + } cb_data->func( cb_data->data, atoken, rtoken ); g_free( atoken ); g_free( rtoken ); |