Changes in protocols/jabber/sasl.c [67ea361:9b02bab]
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
protocols/jabber/sasl.c
r67ea361 r9b02bab 39 39 }; 40 40 41 /* """"""""""""""""""""""""""""""oauth"""""""""""""""""""""""""""""" */42 #define HIPCHAT_SO_CALLED_OAUTH_URL "https://hipchat.com/account/api"43 44 41 xt_status sasl_pkt_mechanisms(struct xt_node *node, gpointer data) 45 42 { … … 48 45 struct xt_node *c, *reply; 49 46 char *s; 50 int sup_plain = 0, sup_digest = 0, sup_gtalk = 0, sup_anonymous = 0 , sup_hipchat_oauth = 0;47 int sup_plain = 0, sup_digest = 0, sup_gtalk = 0, sup_anonymous = 0; 51 48 int want_oauth = FALSE, want_hipchat = FALSE, want_anonymous = FALSE; 52 49 GString *mechs; … … 83 80 } else if (c->text && g_strcasecmp(c->text, "X-OAUTH2") == 0) { 84 81 sup_gtalk = 1; 85 } else if (c->text && g_strcasecmp(c->text, "X-HIPCHAT-OAUTH2") == 0) {86 sup_hipchat_oauth = 1;87 82 } 88 83 … … 95 90 96 91 if (!want_oauth && !sup_plain && !sup_digest) { 97 if ( sup_gtalk || sup_hipchat_oauth) {92 if (!sup_gtalk) { 98 93 imcb_error(ic, "This server requires OAuth " 99 94 "(supported schemes:%s)", mechs->str); … … 115 110 } 116 111 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); 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); 144 126 reply->text_len = strlen(reply->text); 145 g_string_free(gs, TRUE); 146 127 g_free(s); 147 128 } else if (want_oauth) { 148 129 imcb_error(ic, "OAuth requested, but not supported by server"); … … 168 149 /* The rest will be done later, when we receive a <challenge/>. */ 169 150 } else if (sup_plain) { 151 int len; 170 152 GString *gs; 171 153 char *username; … … 192 174 } 193 175 194 reply->text = base64_encode((unsigned char *) gs->str, gs->len); 176 len = gs->len; 177 s = g_string_free(gs, FALSE); 178 179 reply->text = base64_encode((unsigned char *) s, len); 195 180 reply->text_len = strlen(reply->text); 196 g_ string_free(gs, TRUE);181 g_free(s); 197 182 } 198 183 … … 443 428 { 444 429 struct jabber_data *jd = ic->proto_data; 430 char *msg, *url; 445 431 446 432 imcb_log(ic, "Starting OAuth authentication"); … … 448 434 /* Temporary contact, just used to receive the OAuth response. */ 449 435 imcb_add_buddy(ic, JABBER_OAUTH_HANDLE, NULL); 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 } 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); 465 439 imcb_buddy_msg(ic, JABBER_OAUTH_HANDLE, "Respond to this message with the returned " 466 440 "authorization token.", 0, 0); 467 441 442 g_free(msg); 443 g_free(url); 468 444 } 469 445 … … 477 453 return FALSE; 478 454 } 455 456 static void sasl_oauth2_got_token(gpointer data, const char *access_token, const char *refresh_token, 457 const char *error); 479 458 480 459 int sasl_oauth2_get_refresh_token(struct im_connection *ic, const char *msg) … … 507 486 } 508 487 509 void sasl_oauth2_got_token(gpointer data, const char *access_token, const char *refresh_token, const char *error)488 static void sasl_oauth2_got_token(gpointer data, const char *access_token, const char *refresh_token, const char *error) 510 489 { 511 490 struct im_connection *ic = data;
Note: See TracChangeset
for help on using the changeset viewer.