Changeset 64b6635


Ignore:
Timestamp:
2011-12-18T21:56:44Z (12 years ago)
Author:
Wilmer van der Gaast <wilmer@…>
Branches:
master
Children:
9b0ad7e
Parents:
18c6d36
Message:

Restructured and updated code a little bit to support new-style (much better
and "proper" OAuth2) Facebook OAuth support. (And, add wl.offline scope to get
tokens that don't expire after an hour.)

Location:
protocols/jabber
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • protocols/jabber/jabber.c

    r18c6d36 r64b6635  
    152152                        jd->oauth2_service = &oauth2_service_google;
    153153               
    154                 /* For the first login with OAuth, we have to authenticate via the browser.
    155                    For subsequent logins, exchange the refresh token for a valid access
    156                    token (even though the last one maybe didn't expire yet). */
    157                 if( strncmp( acc->pass, "refresh_token=", 14 ) != 0 )
     154                /* First see if we have a refresh token, in which case any
     155                   access token we *might* have has probably expired already
     156                   anyway. */
     157                if( strstr( acc->pass, "refresh_token=" ) )
     158                {
     159                        sasl_oauth2_refresh( ic, acc->pass + 14 );
     160                }
     161                /* If we don't have a refresh token, let's hope the access
     162                   token is still usable. */
     163                else if( strstr( acc->pass, "access_token=" ) )
     164                {
     165                        sasl_oauth2_load_access_token( ic );
     166                        jabber_connect( ic );
     167                }
     168                /* If we don't have any, start the OAuth process now. Don't
     169                   even open an XMPP connection yet. */
     170                else
    158171                {
    159172                        sasl_oauth2_init( ic );
    160173                        ic->flags |= OPT_SLOW_LOGIN;
    161174                }
    162                 else
    163                         sasl_oauth2_refresh( ic, acc->pass + 14 );
    164175        }
    165176        else
  • protocols/jabber/jabber.h

    r18c6d36 r64b6635  
    327327int sasl_oauth2_get_refresh_token( struct im_connection *ic, const char *msg );
    328328int sasl_oauth2_refresh( struct im_connection *ic, const char *refresh_token );
     329int sasl_oauth2_load_access_token( struct im_connection *ic );
    329330
    330331extern const struct oauth2_service oauth2_service_google;
  • protocols/jabber/sasl.c

    r18c6d36 r64b6635  
    5252        "https://oauth.live.com/token",
    5353        "http://www.bitlbee.org/main.php/Messenger/oauth2.html",
    54         "wl.messenger",
     54        "wl.offline_access%20wl.messenger",
    5555        "000000004C06FCD1",
    5656        "IRKlBPzJJAWcY-TbZjiTEJu9tn7XCFaV",
     
    8888                if( c->text && g_strcasecmp( c->text, "PLAIN" ) == 0 )
    8989                        sup_plain = 1;
    90                 if( c->text && g_strcasecmp( c->text, "DIGEST-MD5" ) == 0 )
     90                else if( c->text && g_strcasecmp( c->text, "DIGEST-MD5" ) == 0 )
    9191                        sup_digest = 1;
    92                 if( c->text && g_strcasecmp( c->text, "X-OAUTH2" ) == 0 )
     92                else if( c->text && g_strcasecmp( c->text, "X-OAUTH2" ) == 0 )
    9393                        sup_gtalk = 1;
    94                 if( c->text && g_strcasecmp( c->text, "X-FACEBOOK-PLATFORM" ) == 0 )
     94                else if( c->text && g_strcasecmp( c->text, "X-FACEBOOK-PLATFORM" ) == 0 )
    9595                        sup_fb = 1;
    96                 if( c->text && g_strcasecmp( c->text, "X-MESSENGER-OAUTH2" ) == 0 )
     96                else if( c->text && g_strcasecmp( c->text, "X-MESSENGER-OAUTH2" ) == 0 )
    9797                        sup_ms = 1;
    9898               
     
    135135                reply->text_len = strlen( jd->oauth2_access_token );
    136136        }
    137         else if( sup_fb && want_oauth && strstr( ic->acc->pass, "session_key=" ) )
     137        else if( sup_fb && want_oauth )
    138138        {
    139139                xt_add_attr( reply, "mechanism", "X-FACEBOOK-PLATFORM" );
     
    292292                   and in their Python module. It's all mostly useless because the tokens
    293293                   expire after 24h. */
    294                 GSList *p_in = NULL, *p_out = NULL, *p;
    295                 md5_state_t md5;
    296                 char time[33], *token;
    297                 const char *secret;
     294                GSList *p_in = NULL, *p_out = NULL;
     295                char time[33];
    298296               
    299297                oauth_params_parse( &p_in, dec );
     
    301299                oauth_params_add( &p_out, "method", oauth_params_get( &p_in, "method" ) );
    302300                oauth_params_free( &p_in );
    303                
    304                 token = g_strdup( ic->acc->pass );
    305                 oauth_params_parse( &p_in, token );
    306                 g_free( token );
    307                 oauth_params_add( &p_out, "session_key", oauth_params_get( &p_in, "session_key" ) );
    308301               
    309302                g_snprintf( time, sizeof( time ), "%lld", (long long) ( gettime() * 1000 ) );
     
    312305                oauth_params_add( &p_out, "v", "1.0" );
    313306                oauth_params_add( &p_out, "format", "XML" );
    314                
    315                 md5_init( &md5 );
    316                 for( p = p_out; p; p = p->next )
    317                         md5_append( &md5, p->data, strlen( p->data ) );
    318                
    319                 secret = oauth_params_get( &p_in, "secret" );
    320                 if( secret )
    321                         md5_append( &md5, (unsigned char*) secret, strlen( secret ) );
    322                 md5_finish_ascii( &md5, time );
    323                 oauth_params_add( &p_out, "sig", time );
     307                oauth_params_add( &p_out, "access_token", jd->oauth2_access_token );
    324308               
    325309                reply = oauth_params_string( p_out );
    326310                oauth_params_free( &p_out );
    327                 oauth_params_free( &p_in );
    328311        }
    329312        else if( !( s = sasl_get_part( dec, "rspauth" ) ) )
     
    521504}
    522505
     506int sasl_oauth2_load_access_token( struct im_connection *ic )
     507{
     508        struct jabber_data *jd = ic->proto_data;
     509        GSList *p_in = NULL;
     510       
     511        oauth_params_parse( &p_in, ic->acc->pass );
     512        jd->oauth2_access_token = g_strdup( oauth_params_get( &p_in, "access_token" ) );
     513        oauth_params_free( &p_in );
     514       
     515        return jd->oauth2_access_token != NULL;
     516}
     517
    523518static void sasl_oauth2_got_token( gpointer data, const char *access_token, const char *refresh_token )
    524519{
Note: See TracChangeset for help on using the changeset viewer.