Changeset 537d9b9 for protocols/jabber/sasl.c
- Timestamp:
- 2016-11-20T08:40:36Z (8 years ago)
- Children:
- 3f44e43
- Parents:
- ba52ac5 (diff), 9f03c47 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
protocols/jabber/sasl.c
rba52ac5 r537d9b9 39 39 }; 40 40 41 /* """"""""""""""""""""""""""""""oauth"""""""""""""""""""""""""""""" */ 42 #define HIPCHAT_SO_CALLED_OAUTH_URL "https://hipchat.com/account/api" 43 41 44 xt_status sasl_pkt_mechanisms(struct xt_node *node, gpointer data) 42 45 { … … 45 48 struct xt_node *c, *reply; 46 49 char *s; 47 int sup_plain = 0, sup_digest = 0, sup_gtalk = 0, sup_anonymous = 0 ;50 int sup_plain = 0, sup_digest = 0, sup_gtalk = 0, sup_anonymous = 0, sup_hipchat_oauth = 0; 48 51 int want_oauth = FALSE, want_hipchat = FALSE, want_anonymous = FALSE; 49 52 GString *mechs; … … 80 83 } else if (c->text && g_strcasecmp(c->text, "X-OAUTH2") == 0) { 81 84 sup_gtalk = 1; 85 } else if (c->text && g_strcasecmp(c->text, "X-HIPCHAT-OAUTH2") == 0) { 86 sup_hipchat_oauth = 1; 82 87 } 83 88 … … 90 95 91 96 if (!want_oauth && !sup_plain && !sup_digest) { 92 if ( !sup_gtalk) {97 if (sup_gtalk || sup_hipchat_oauth) { 93 98 imcb_error(ic, "This server requires OAuth " 94 99 "(supported schemes:%s)", mechs->str); … … 110 115 } 111 116 112 if (sup_gtalk && want_oauth) { 113 int len; 114 115 /* X-OAUTH2 is, not *the* standard OAuth2 SASL/XMPP implementation. 116 It's currently used by GTalk and vaguely documented on 117 http://code.google.com/apis/cloudprint/docs/rawxmpp.html . */ 118 xt_add_attr(reply, "mechanism", "X-OAUTH2"); 119 120 len = strlen(jd->username) + strlen(jd->oauth2_access_token) + 2; 121 s = g_malloc(len + 1); 122 s[0] = 0; 123 strcpy(s + 1, jd->username); 124 strcpy(s + 2 + strlen(jd->username), jd->oauth2_access_token); 125 reply->text = base64_encode((unsigned char *) s, len); 117 if ((sup_gtalk || sup_hipchat_oauth) && want_oauth) { 118 GString *gs; 119 120 gs = g_string_sized_new(128); 121 122 g_string_append_c(gs, '\0'); 123 124 if (sup_gtalk) { 125 /* X-OAUTH2 is not *the* standard OAuth2 SASL/XMPP implementation. 126 It's currently used by GTalk and vaguely documented on 127 http://code.google.com/apis/cloudprint/docs/rawxmpp.html */ 128 xt_add_attr(reply, "mechanism", "X-OAUTH2"); 129 130 g_string_append(gs, jd->username); 131 g_string_append_c(gs, '\0'); 132 g_string_append(gs, jd->oauth2_access_token); 133 } else if (sup_hipchat_oauth) { 134 /* Hipchat's variant, not standard either, is documented here: 135 https://docs.atlassian.com/hipchat.xmpp/latest/xmpp/auth.html */ 136 xt_add_attr(reply, "mechanism", "oauth2"); 137 138 g_string_append(gs, jd->oauth2_access_token); 139 g_string_append_c(gs, '\0'); 140 g_string_append(gs, set_getstr(&ic->acc->set, "resource")); 141 } 142 143 reply->text = base64_encode((unsigned char *) gs->str, gs->len); 126 144 reply->text_len = strlen(reply->text); 127 g_free(s); 145 g_string_free(gs, TRUE); 146 128 147 } else if (want_oauth) { 129 148 imcb_error(ic, "OAuth requested, but not supported by server"); … … 149 168 /* The rest will be done later, when we receive a <challenge/>. */ 150 169 } else if (sup_plain) { 151 int len;152 170 GString *gs; 153 171 char *username; … … 174 192 } 175 193 176 len = gs->len; 177 s = g_string_free(gs, FALSE); 178 179 reply->text = base64_encode((unsigned char *) s, len); 194 reply->text = base64_encode((unsigned char *) gs->str, gs->len); 180 195 reply->text_len = strlen(reply->text); 181 g_ free(s);196 g_string_free(gs, TRUE); 182 197 } 183 198 … … 428 443 { 429 444 struct jabber_data *jd = ic->proto_data; 430 char *msg, *url;431 445 432 446 imcb_log(ic, "Starting OAuth authentication"); … … 434 448 /* Temporary contact, just used to receive the OAuth response. */ 435 449 imcb_add_buddy(ic, JABBER_OAUTH_HANDLE, NULL); 436 url = oauth2_url(jd->oauth2_service); 437 msg = g_strdup_printf("Open this URL in your browser to authenticate: %s", url); 438 imcb_buddy_msg(ic, JABBER_OAUTH_HANDLE, msg, 0, 0); 450 451 if (jd->flags & JFLAG_HIPCHAT) { 452 imcb_buddy_msg(ic, JABBER_OAUTH_HANDLE, 453 "Open this URL and generate a token with 'View Group' and 'Send Message' scopes: " 454 HIPCHAT_SO_CALLED_OAUTH_URL, 0, 0); 455 } else { 456 char *msg, *url; 457 458 url = oauth2_url(jd->oauth2_service); 459 msg = g_strdup_printf("Open this URL in your browser to authenticate: %s", url); 460 imcb_buddy_msg(ic, JABBER_OAUTH_HANDLE, msg, 0, 0); 461 462 g_free(msg); 463 g_free(url); 464 } 439 465 imcb_buddy_msg(ic, JABBER_OAUTH_HANDLE, "Respond to this message with the returned " 440 466 "authorization token.", 0, 0); 441 467 442 g_free(msg);443 g_free(url);444 468 } 445 469 … … 453 477 return FALSE; 454 478 } 455 456 static void sasl_oauth2_got_token(gpointer data, const char *access_token, const char *refresh_token,457 const char *error);458 479 459 480 int sasl_oauth2_get_refresh_token(struct im_connection *ic, const char *msg) … … 486 507 } 487 508 488 staticvoid sasl_oauth2_got_token(gpointer data, const char *access_token, const char *refresh_token, const char *error)509 void sasl_oauth2_got_token(gpointer data, const char *access_token, const char *refresh_token, const char *error) 489 510 { 490 511 struct im_connection *ic = data;
Note: See TracChangeset
for help on using the changeset viewer.