Changeset 18c6d36 for lib


Ignore:
Timestamp:
2011-12-18T19:25:44Z (12 years ago)
Author:
Wilmer van der Gaast <wilmer@…>
Branches:
master
Children:
64b6635
Parents:
6e9ae72
Message:

More generic OAuth support now. Should work well for all GTalk accounts now
and somewhat for MS Messenger. The fb part needs different parsing of the
authorize request, and possibly some other work.

Location:
lib
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • lib/oauth2.c

    r6e9ae72 r18c6d36  
    2828#include "url.h"
    2929
    30 struct oauth2_service oauth2_service_google =
    31 {
    32         "https://accounts.google.com/o/oauth2/auth",
    33         "https://accounts.google.com/o/oauth2/token",
    34         "urn:ietf:wg:oauth:2.0:oob",
    35         "783993391592.apps.googleusercontent.com",
    36         "6C-Zgf7Tr7gEQTPlBhMUgo7R",
    37 };
    38 struct oauth2_service oauth2_service_facebook =
    39 {
    40         "https://www.facebook.com/dialog/oauth",
    41         "https://graph.facebook.com/oauth/access_token",
    42         "http://www.bitlbee.org/main.php/fb.html",
    43         "126828914005625",
    44         "4b100f0f244d620bf3f15f8b217d4c32",
    45 };
    46 
    47 char *oauth2_url( const struct oauth2_service *sp, const char *scope )
     30char *oauth2_url( const struct oauth2_service *sp )
    4831{
    4932        return g_strconcat( sp->auth_url,
    50                             "?scope=", scope,
     33                            "?scope=", sp->scope,
    5134                            "&response_type=code"
    5235                            "&redirect_uri=", sp->redirect_url,
     
    121104        char *atoken = NULL, *rtoken = NULL;
    122105       
     106        if( getenv( "BITLBEE_DEBUG" ) && req->reply_body )
     107                printf( "%s\n", req->reply_body );
     108       
    123109        if( req->status_code == 200 )
    124110        {
    125111                atoken = oauth2_json_dumb_get( req->reply_body, "access_token" );
    126112                rtoken = oauth2_json_dumb_get( req->reply_body, "refresh_token" );
     113                if( getenv( "BITLBEE_DEBUG" ) )
     114                        printf( "Extracted atoken=%s rtoken=%s\n", atoken, rtoken );
    127115        }
    128116        cb_data->func( cb_data->data, atoken, rtoken );
  • lib/oauth2.h

    r6e9ae72 r18c6d36  
    3232        char *token_url;
    3333        char *redirect_url;
     34        char *scope;
    3435        char *consumer_key;
    3536        char *consumer_secret;
    3637};
    37 
    38 /* Currently suitable for authenticating to Google Talk only, and only for
    39    accounts that have 2-factor authorization enabled. */
    40 extern struct oauth2_service oauth2_service_google;
    41 
    42 extern struct oauth2_service oauth2_service_facebook;
    4338
    4439#define OAUTH2_AUTH_CODE "authorization_code"
     
    4742/* Generate a URL the user should open in his/her browser to get an
    4843   authorization code. */
    49 char *oauth2_url( const struct oauth2_service *sp, const char *scope );
     44char *oauth2_url( const struct oauth2_service *sp );
    5045
    5146/* Exchanges an auth code or refresh token for an access token.
Note: See TracChangeset for help on using the changeset viewer.