Changeset 18c6d36 for protocols/jabber
- Timestamp:
- 2011-12-18T19:25:44Z (13 years ago)
- Branches:
- master
- Children:
- 64b6635
- Parents:
- 6e9ae72
- Location:
- protocols/jabber
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
protocols/jabber/jabber.c
r6e9ae72 r18c6d36 144 144 { 145 145 jd->fd = jd->r_inpa = jd->w_inpa = -1; 146 147 if( strstr( jd->server, ".live.com" ) ) 148 jd->oauth2_service = &oauth2_service_mslive; 149 else if( strstr( jd->server, ".facebook.com" ) ) 150 jd->oauth2_service = &oauth2_service_facebook; 151 else 152 jd->oauth2_service = &oauth2_service_google; 146 153 147 154 /* For the first login with OAuth, we have to authenticate via the browser. -
protocols/jabber/jabber.h
r6e9ae72 r18c6d36 95 95 char *server; /* username@SERVER -=> server/domain, not hostname */ 96 96 97 const struct oauth2_service *oauth2_service; 97 98 char *oauth2_access_token; 98 99 … … 327 328 int sasl_oauth2_refresh( struct im_connection *ic, const char *refresh_token ); 328 329 330 extern const struct oauth2_service oauth2_service_google; 331 extern const struct oauth2_service oauth2_service_facebook; 332 extern const struct oauth2_service oauth2_service_mslive; 333 329 334 /* conference.c */ 330 335 struct groupchat *jabber_chat_join( struct im_connection *ic, const char *room, const char *nick, const char *password ); -
protocols/jabber/sasl.c
r6e9ae72 r18c6d36 29 29 #include "oauth.h" 30 30 31 const struct oauth2_service oauth2_service_google = 32 { 33 "https://accounts.google.com/o/oauth2/auth", 34 "https://accounts.google.com/o/oauth2/token", 35 "urn:ietf:wg:oauth:2.0:oob", 36 "https://www.googleapis.com/auth/googletalk", 37 "783993391592.apps.googleusercontent.com", 38 "6C-Zgf7Tr7gEQTPlBhMUgo7R", 39 }; 40 const struct oauth2_service oauth2_service_facebook = 41 { 42 "https://www.facebook.com/dialog/oauth", 43 "https://graph.facebook.com/oauth/access_token", 44 "http://www.bitlbee.org/main.php/Facebook/oauth2.html", 45 "offline_access,xmpp_login", 46 "126828914005625", 47 "4b100f0f244d620bf3f15f8b217d4c32", 48 }; 49 const struct oauth2_service oauth2_service_mslive = 50 { 51 "https://oauth.live.com/authorize", 52 "https://oauth.live.com/token", 53 "http://www.bitlbee.org/main.php/Messenger/oauth2.html", 54 "wl.messenger", 55 "000000004C06FCD1", 56 "IRKlBPzJJAWcY-TbZjiTEJu9tn7XCFaV", 57 }; 58 31 59 xt_status sasl_pkt_mechanisms( struct xt_node *node, gpointer data ) 32 60 { … … 35 63 struct xt_node *c, *reply; 36 64 char *s; 37 int sup_plain = 0, sup_digest = 0, sup_oauth2 = 0, sup_fb = 0; 65 int sup_plain = 0, sup_digest = 0, sup_gtalk = 0, sup_fb = 0, sup_ms = 0; 66 int want_oauth = FALSE; 38 67 39 68 if( !sasl_supported( ic ) ) … … 62 91 sup_digest = 1; 63 92 if( c->text && g_strcasecmp( c->text, "X-OAUTH2" ) == 0 ) 64 sup_ oauth2= 1;93 sup_gtalk = 1; 65 94 if( c->text && g_strcasecmp( c->text, "X-FACEBOOK-PLATFORM" ) == 0 ) 66 95 sup_fb = 1; 96 if( c->text && g_strcasecmp( c->text, "X-MESSENGER-OAUTH2" ) == 0 ) 97 sup_ms = 1; 67 98 68 99 c = c->next; 69 100 } 70 101 71 if( !sup_plain && !sup_digest )102 if( !sup_plain && !sup_digest && !sup_gtalk && !sup_fb && !sup_ms ) 72 103 { 73 104 imcb_error( ic, "No known SASL authentication schemes supported" ); … … 78 109 reply = xt_new_node( "auth", NULL, NULL ); 79 110 xt_add_attr( reply, "xmlns", XMLNS_SASL ); 80 81 if( set_getbool( &ic->acc->set, "oauth" ) ) 111 want_oauth = set_getbool( &ic->acc->set, "oauth" ); 112 113 if( sup_gtalk && want_oauth ) 82 114 { 83 115 int len; 84 85 if( !sup_oauth2 )86 {87 imcb_error( ic, "OAuth requested, but not supported by server" );88 imc_logout( ic, FALSE );89 xt_free_node( reply );90 return XT_ABORT;91 }92 116 93 117 /* X-OAUTH2 is, not *the* standard OAuth2 SASL/XMPP implementation. … … 105 129 g_free( s ); 106 130 } 107 else if( sup_fb && strstr( ic->acc->pass, "session_key=" ) ) 131 else if( sup_ms && want_oauth ) 132 { 133 xt_add_attr( reply, "mechanism", "X-MESSENGER-OAUTH2" ); 134 reply->text = g_strdup( jd->oauth2_access_token ); 135 reply->text_len = strlen( jd->oauth2_access_token ); 136 } 137 else if( sup_fb && want_oauth && strstr( ic->acc->pass, "session_key=" ) ) 108 138 { 109 139 xt_add_attr( reply, "mechanism", "X-FACEBOOK-PLATFORM" ); 110 140 jd->flags |= JFLAG_SASL_FB; 141 } 142 else if( want_oauth ) 143 { 144 imcb_error( ic, "OAuth requested, but not supported by server" ); 145 imc_logout( ic, FALSE ); 146 xt_free_node( reply ); 147 return XT_ABORT; 111 148 } 112 149 else if( sup_digest ) … … 428 465 void sasl_oauth2_init( struct im_connection *ic ) 429 466 { 467 struct jabber_data *jd = ic->proto_data; 430 468 char *msg, *url; 431 469 … … 434 472 /* Temporary contact, just used to receive the OAuth response. */ 435 473 imcb_add_buddy( ic, "jabber_oauth", NULL ); 436 url = oauth2_url( &oauth2_service_google, 437 "https://www.googleapis.com/auth/googletalk" ); 474 url = oauth2_url( jd->oauth2_service ); 438 475 msg = g_strdup_printf( "Open this URL in your browser to authenticate: %s", url ); 439 476 imcb_buddy_msg( ic, "jabber_oauth", msg, 0, 0 ); … … 457 494 int sasl_oauth2_get_refresh_token( struct im_connection *ic, const char *msg ) 458 495 { 496 struct jabber_data *jd = ic->proto_data; 459 497 char *code; 460 498 int ret; … … 468 506 code = g_strdup( msg ); 469 507 g_strstrip( code ); 470 ret = oauth2_access_token( &oauth2_service_google, OAUTH2_AUTH_CODE,508 ret = oauth2_access_token( jd->oauth2_service, OAUTH2_AUTH_CODE, 471 509 code, sasl_oauth2_got_token, ic ); 472 510 … … 477 515 int sasl_oauth2_refresh( struct im_connection *ic, const char *refresh_token ) 478 516 { 479 return oauth2_access_token( &oauth2_service_google, OAUTH2_AUTH_REFRESH, 517 struct jabber_data *jd = ic->proto_data; 518 519 return oauth2_access_token( jd->oauth2_service, OAUTH2_AUTH_REFRESH, 480 520 refresh_token, sasl_oauth2_got_token, ic ); 481 521 }
Note: See TracChangeset
for help on using the changeset viewer.