- Timestamp:
- 2011-12-18T21:56:44Z (13 years ago)
- Branches:
- master
- Children:
- 9b0ad7e
- Parents:
- 18c6d36
- Location:
- protocols/jabber
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
protocols/jabber/jabber.c
r18c6d36 r64b6635 152 152 jd->oauth2_service = &oauth2_service_google; 153 153 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 158 171 { 159 172 sasl_oauth2_init( ic ); 160 173 ic->flags |= OPT_SLOW_LOGIN; 161 174 } 162 else163 sasl_oauth2_refresh( ic, acc->pass + 14 );164 175 } 165 176 else -
protocols/jabber/jabber.h
r18c6d36 r64b6635 327 327 int sasl_oauth2_get_refresh_token( struct im_connection *ic, const char *msg ); 328 328 int sasl_oauth2_refresh( struct im_connection *ic, const char *refresh_token ); 329 int sasl_oauth2_load_access_token( struct im_connection *ic ); 329 330 330 331 extern const struct oauth2_service oauth2_service_google; -
protocols/jabber/sasl.c
r18c6d36 r64b6635 52 52 "https://oauth.live.com/token", 53 53 "http://www.bitlbee.org/main.php/Messenger/oauth2.html", 54 "wl. messenger",54 "wl.offline_access%20wl.messenger", 55 55 "000000004C06FCD1", 56 56 "IRKlBPzJJAWcY-TbZjiTEJu9tn7XCFaV", … … 88 88 if( c->text && g_strcasecmp( c->text, "PLAIN" ) == 0 ) 89 89 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 ) 91 91 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 ) 93 93 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 ) 95 95 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 ) 97 97 sup_ms = 1; 98 98 … … 135 135 reply->text_len = strlen( jd->oauth2_access_token ); 136 136 } 137 else if( sup_fb && want_oauth && strstr( ic->acc->pass, "session_key=" ))137 else if( sup_fb && want_oauth ) 138 138 { 139 139 xt_add_attr( reply, "mechanism", "X-FACEBOOK-PLATFORM" ); … … 292 292 and in their Python module. It's all mostly useless because the tokens 293 293 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]; 298 296 299 297 oauth_params_parse( &p_in, dec ); … … 301 299 oauth_params_add( &p_out, "method", oauth_params_get( &p_in, "method" ) ); 302 300 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" ) );308 301 309 302 g_snprintf( time, sizeof( time ), "%lld", (long long) ( gettime() * 1000 ) ); … … 312 305 oauth_params_add( &p_out, "v", "1.0" ); 313 306 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 ); 324 308 325 309 reply = oauth_params_string( p_out ); 326 310 oauth_params_free( &p_out ); 327 oauth_params_free( &p_in );328 311 } 329 312 else if( !( s = sasl_get_part( dec, "rspauth" ) ) ) … … 521 504 } 522 505 506 int 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 523 518 static void sasl_oauth2_got_token( gpointer data, const char *access_token, const char *refresh_token ) 524 519 {
Note: See TracChangeset
for help on using the changeset viewer.