[be28fe7] | 1 | /***************************************************************************\ |
---|
| 2 | * * |
---|
| 3 | * BitlBee - An IRC to IM gateway * |
---|
| 4 | * Simple OAuth client (consumer) implementation. * |
---|
| 5 | * * |
---|
| 6 | * Copyright 2010 Wilmer van der Gaast <wilmer@gaast.net> * |
---|
| 7 | * * |
---|
| 8 | * This library is free software; you can redistribute it and/or * |
---|
| 9 | * modify it under the terms of the GNU Lesser General Public * |
---|
| 10 | * License as published by the Free Software Foundation, version * |
---|
| 11 | * 2.1. * |
---|
| 12 | * * |
---|
| 13 | * This library is distributed in the hope that it will be useful, * |
---|
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * |
---|
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * |
---|
| 16 | * Lesser General Public License for more details. * |
---|
| 17 | * * |
---|
| 18 | * You should have received a copy of the GNU Lesser General Public License * |
---|
| 19 | * along with this library; if not, write to the Free Software Foundation, * |
---|
| 20 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * |
---|
| 21 | * * |
---|
| 22 | \***************************************************************************/ |
---|
| 23 | |
---|
| 24 | #include <glib.h> |
---|
| 25 | #include <gmodule.h> |
---|
| 26 | #include <stdlib.h> |
---|
| 27 | #include <string.h> |
---|
[da2efd4] | 28 | #include "http_client.h" |
---|
[be28fe7] | 29 | #include "base64.h" |
---|
| 30 | #include "misc.h" |
---|
| 31 | #include "sha1.h" |
---|
[da2efd4] | 32 | #include "url.h" |
---|
[acba168] | 33 | #include "oauth.h" |
---|
[be28fe7] | 34 | |
---|
| 35 | #define HMAC_BLOCK_SIZE 64 |
---|
| 36 | |
---|
| 37 | static char *oauth_sign( const char *method, const char *url, |
---|
[c2ecadc] | 38 | const char *params, struct oauth_info *oi ) |
---|
[be28fe7] | 39 | { |
---|
| 40 | sha1_state_t sha1; |
---|
| 41 | uint8_t hash[sha1_hash_size]; |
---|
| 42 | uint8_t key[HMAC_BLOCK_SIZE+1]; |
---|
| 43 | char *s; |
---|
| 44 | int i; |
---|
| 45 | |
---|
| 46 | /* Create K. If our current key is >64 chars we have to hash it, |
---|
| 47 | otherwise just pad. */ |
---|
| 48 | memset( key, 0, HMAC_BLOCK_SIZE ); |
---|
[c2ecadc] | 49 | i = strlen( oi->sp->consumer_secret ) + 1 + ( oi->token_secret ? strlen( oi->token_secret ) : 0 ); |
---|
[be28fe7] | 50 | if( i > HMAC_BLOCK_SIZE ) |
---|
| 51 | { |
---|
| 52 | sha1_init( &sha1 ); |
---|
[c2ecadc] | 53 | sha1_append( &sha1, (uint8_t*) oi->sp->consumer_secret, strlen( oi->sp->consumer_secret ) ); |
---|
[da2efd4] | 54 | sha1_append( &sha1, (uint8_t*) "&", 1 ); |
---|
[c2ecadc] | 55 | if( oi->token_secret ) |
---|
| 56 | sha1_append( &sha1, (uint8_t*) oi->token_secret, strlen( oi->token_secret ) ); |
---|
[be28fe7] | 57 | sha1_finish( &sha1, key ); |
---|
| 58 | } |
---|
| 59 | else |
---|
| 60 | { |
---|
[da2efd4] | 61 | g_snprintf( (gchar*) key, HMAC_BLOCK_SIZE + 1, "%s&%s", |
---|
[daae10f] | 62 | oi->sp->consumer_secret, oi->token_secret ? oi->token_secret : "" ); |
---|
[be28fe7] | 63 | } |
---|
| 64 | |
---|
| 65 | /* Inner part: H(K XOR 0x36, text) */ |
---|
| 66 | sha1_init( &sha1 ); |
---|
| 67 | |
---|
| 68 | for( i = 0; i < HMAC_BLOCK_SIZE; i ++ ) |
---|
| 69 | key[i] ^= 0x36; |
---|
| 70 | sha1_append( &sha1, key, HMAC_BLOCK_SIZE ); |
---|
| 71 | |
---|
| 72 | /* OAuth: text = method&url¶ms, all http_encoded. */ |
---|
| 73 | sha1_append( &sha1, (const uint8_t*) method, strlen( method ) ); |
---|
| 74 | sha1_append( &sha1, (const uint8_t*) "&", 1 ); |
---|
| 75 | |
---|
| 76 | s = g_new0( char, strlen( url ) * 3 + 1 ); |
---|
| 77 | strcpy( s, url ); |
---|
| 78 | http_encode( s ); |
---|
| 79 | sha1_append( &sha1, (const uint8_t*) s, strlen( s ) ); |
---|
| 80 | sha1_append( &sha1, (const uint8_t*) "&", 1 ); |
---|
| 81 | g_free( s ); |
---|
| 82 | |
---|
| 83 | s = g_new0( char, strlen( params ) * 3 + 1 ); |
---|
| 84 | strcpy( s, params ); |
---|
| 85 | http_encode( s ); |
---|
| 86 | sha1_append( &sha1, (const uint8_t*) s, strlen( s ) ); |
---|
| 87 | g_free( s ); |
---|
| 88 | |
---|
| 89 | sha1_finish( &sha1, hash ); |
---|
| 90 | |
---|
| 91 | /* Final result: H(K XOR 0x5C, inner stuff) */ |
---|
| 92 | sha1_init( &sha1 ); |
---|
| 93 | for( i = 0; i < HMAC_BLOCK_SIZE; i ++ ) |
---|
| 94 | key[i] ^= 0x36 ^ 0x5c; |
---|
| 95 | sha1_append( &sha1, key, HMAC_BLOCK_SIZE ); |
---|
| 96 | sha1_append( &sha1, hash, sha1_hash_size ); |
---|
| 97 | sha1_finish( &sha1, hash ); |
---|
| 98 | |
---|
[ee84bdb] | 99 | /* base64_encode + HTTP escape it (both consumers |
---|
| 100 | need it that away) and we're done. */ |
---|
| 101 | s = base64_encode( hash, sha1_hash_size ); |
---|
| 102 | s = g_realloc( s, strlen( s ) * 3 + 1 ); |
---|
| 103 | http_encode( s ); |
---|
| 104 | |
---|
| 105 | return s; |
---|
[be28fe7] | 106 | } |
---|
[da2efd4] | 107 | |
---|
| 108 | static char *oauth_nonce() |
---|
| 109 | { |
---|
[ce617f0] | 110 | unsigned char bytes[21]; |
---|
| 111 | char *ret = g_new0( char, sizeof( bytes) / 3 * 4 + 1 ); |
---|
[da2efd4] | 112 | |
---|
| 113 | random_bytes( bytes, sizeof( bytes ) ); |
---|
[ce617f0] | 114 | base64_encode_real( bytes, sizeof( bytes), (unsigned char*) ret, "0123456789" |
---|
| 115 | "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0A" ); |
---|
| 116 | |
---|
| 117 | return ret; |
---|
[da2efd4] | 118 | } |
---|
| 119 | |
---|
| 120 | void oauth_params_add( GSList **params, const char *key, const char *value ) |
---|
| 121 | { |
---|
| 122 | char *item; |
---|
| 123 | |
---|
| 124 | item = g_strdup_printf( "%s=%s", key, value ); |
---|
| 125 | *params = g_slist_insert_sorted( *params, item, (GCompareFunc) strcmp ); |
---|
| 126 | } |
---|
| 127 | |
---|
| 128 | void oauth_params_del( GSList **params, const char *key ) |
---|
| 129 | { |
---|
| 130 | int key_len = strlen( key ); |
---|
| 131 | GSList *l, *n; |
---|
| 132 | |
---|
| 133 | for( l = *params; l; l = n ) |
---|
| 134 | { |
---|
| 135 | n = l->next; |
---|
| 136 | |
---|
| 137 | if( strncmp( (char*) l->data, key, key_len ) == 0 && |
---|
| 138 | ((char*)l->data)[key_len] == '=' ) |
---|
| 139 | { |
---|
| 140 | g_free( l->data ); |
---|
[b2bc25c] | 141 | *params = g_slist_remove( *params, l->data ); |
---|
[da2efd4] | 142 | } |
---|
| 143 | } |
---|
| 144 | } |
---|
| 145 | |
---|
| 146 | void oauth_params_set( GSList **params, const char *key, const char *value ) |
---|
| 147 | { |
---|
| 148 | oauth_params_del( params, key ); |
---|
| 149 | oauth_params_add( params, key, value ); |
---|
| 150 | } |
---|
| 151 | |
---|
| 152 | const char *oauth_params_get( GSList **params, const char *key ) |
---|
| 153 | { |
---|
| 154 | int key_len = strlen( key ); |
---|
| 155 | GSList *l; |
---|
| 156 | |
---|
| 157 | for( l = *params; l; l = l->next ) |
---|
| 158 | { |
---|
| 159 | if( strncmp( (char*) l->data, key, key_len ) == 0 && |
---|
| 160 | ((char*)l->data)[key_len] == '=' ) |
---|
| 161 | return (const char*) l->data + key_len + 1; |
---|
| 162 | } |
---|
| 163 | |
---|
| 164 | return NULL; |
---|
| 165 | } |
---|
| 166 | |
---|
[508c340] | 167 | static void oauth_params_parse( GSList **params, char *in ) |
---|
[da2efd4] | 168 | { |
---|
[ee84bdb] | 169 | char *amp, *eq, *s; |
---|
[da2efd4] | 170 | |
---|
| 171 | while( in && *in ) |
---|
| 172 | { |
---|
| 173 | eq = strchr( in, '=' ); |
---|
| 174 | if( !eq ) |
---|
| 175 | break; |
---|
| 176 | |
---|
| 177 | *eq = '\0'; |
---|
| 178 | if( ( amp = strchr( eq + 1, '&' ) ) ) |
---|
| 179 | *amp = '\0'; |
---|
| 180 | |
---|
[ee84bdb] | 181 | s = g_strdup( eq + 1 ); |
---|
| 182 | http_decode( s ); |
---|
| 183 | oauth_params_add( params, in, s ); |
---|
| 184 | g_free( s ); |
---|
[da2efd4] | 185 | |
---|
| 186 | *eq = '='; |
---|
| 187 | if( amp == NULL ) |
---|
| 188 | break; |
---|
| 189 | |
---|
| 190 | *amp = '&'; |
---|
| 191 | in = amp + 1; |
---|
| 192 | } |
---|
| 193 | } |
---|
| 194 | |
---|
| 195 | void oauth_params_free( GSList **params ) |
---|
| 196 | { |
---|
| 197 | while( params && *params ) |
---|
| 198 | { |
---|
| 199 | g_free( (*params)->data ); |
---|
| 200 | *params = g_slist_remove( *params, (*params)->data ); |
---|
| 201 | } |
---|
| 202 | } |
---|
| 203 | |
---|
| 204 | char *oauth_params_string( GSList *params ) |
---|
| 205 | { |
---|
| 206 | GSList *l; |
---|
| 207 | GString *str = g_string_new( "" ); |
---|
| 208 | |
---|
| 209 | for( l = params; l; l = l->next ) |
---|
| 210 | { |
---|
[ee84bdb] | 211 | char *s, *eq; |
---|
| 212 | |
---|
| 213 | s = g_malloc( strlen( l->data ) * 3 + 1 ); |
---|
| 214 | strcpy( s, l->data ); |
---|
| 215 | if( ( eq = strchr( s, '=' ) ) ) |
---|
| 216 | http_encode( eq + 1 ); |
---|
| 217 | g_string_append( str, s ); |
---|
| 218 | g_free( s ); |
---|
| 219 | |
---|
[da2efd4] | 220 | if( l->next ) |
---|
| 221 | g_string_append_c( str, '&' ); |
---|
| 222 | } |
---|
| 223 | |
---|
| 224 | return g_string_free( str, FALSE ); |
---|
| 225 | } |
---|
| 226 | |
---|
[18dbb20] | 227 | void oauth_info_free( struct oauth_info *info ) |
---|
| 228 | { |
---|
| 229 | if( info ) |
---|
| 230 | { |
---|
[c2ecadc] | 231 | g_free( info->auth_url ); |
---|
[18dbb20] | 232 | g_free( info->request_token ); |
---|
[c2ecadc] | 233 | g_free( info->token ); |
---|
| 234 | g_free( info->token_secret ); |
---|
[93cc86f] | 235 | oauth_params_free( &info->params ); |
---|
[18dbb20] | 236 | g_free( info ); |
---|
| 237 | } |
---|
| 238 | } |
---|
| 239 | |
---|
[3b878a1] | 240 | static void oauth_add_default_params( GSList **params, const struct oauth_service *sp ) |
---|
[b2bc25c] | 241 | { |
---|
| 242 | char *s; |
---|
| 243 | |
---|
[c2ecadc] | 244 | oauth_params_set( params, "oauth_consumer_key", sp->consumer_key ); |
---|
[b2bc25c] | 245 | oauth_params_set( params, "oauth_signature_method", "HMAC-SHA1" ); |
---|
| 246 | |
---|
| 247 | s = g_strdup_printf( "%d", (int) time( NULL ) ); |
---|
| 248 | oauth_params_set( params, "oauth_timestamp", s ); |
---|
| 249 | g_free( s ); |
---|
| 250 | |
---|
| 251 | s = oauth_nonce(); |
---|
| 252 | oauth_params_set( params, "oauth_nonce", s ); |
---|
| 253 | g_free( s ); |
---|
| 254 | |
---|
| 255 | oauth_params_set( params, "oauth_version", "1.0" ); |
---|
| 256 | } |
---|
| 257 | |
---|
[c2ecadc] | 258 | static void *oauth_post_request( const char *url, GSList **params_, http_input_function func, struct oauth_info *oi ) |
---|
[da2efd4] | 259 | { |
---|
| 260 | GSList *params = NULL; |
---|
| 261 | char *s, *params_s, *post; |
---|
| 262 | void *req; |
---|
| 263 | url_t url_p; |
---|
| 264 | |
---|
| 265 | if( !url_set( &url_p, url ) ) |
---|
| 266 | { |
---|
| 267 | oauth_params_free( params_ ); |
---|
| 268 | return NULL; |
---|
| 269 | } |
---|
| 270 | |
---|
| 271 | if( params_ ) |
---|
| 272 | params = *params_; |
---|
| 273 | |
---|
[c2ecadc] | 274 | oauth_add_default_params( ¶ms, oi->sp ); |
---|
[da2efd4] | 275 | |
---|
| 276 | params_s = oauth_params_string( params ); |
---|
[0bff877] | 277 | oauth_params_free( ¶ms ); |
---|
[da2efd4] | 278 | |
---|
[c2ecadc] | 279 | s = oauth_sign( "POST", url, params_s, oi ); |
---|
[da2efd4] | 280 | post = g_strdup_printf( "%s&oauth_signature=%s", params_s, s ); |
---|
| 281 | g_free( params_s ); |
---|
| 282 | g_free( s ); |
---|
| 283 | |
---|
| 284 | s = g_strdup_printf( "POST %s HTTP/1.0\r\n" |
---|
| 285 | "Host: %s\r\n" |
---|
| 286 | "Content-Type: application/x-www-form-urlencoded\r\n" |
---|
| 287 | "Content-Length: %zd\r\n" |
---|
[2423c93] | 288 | "Connection: close\r\n" |
---|
[da2efd4] | 289 | "\r\n" |
---|
| 290 | "%s", url_p.file, url_p.host, strlen( post ), post ); |
---|
| 291 | g_free( post ); |
---|
| 292 | |
---|
| 293 | req = http_dorequest( url_p.host, url_p.port, url_p.proto == PROTO_HTTPS, |
---|
[c2ecadc] | 294 | s, func, oi ); |
---|
[da2efd4] | 295 | g_free( s ); |
---|
| 296 | |
---|
| 297 | return req; |
---|
| 298 | } |
---|
| 299 | |
---|
[346dfd9] | 300 | static void oauth_request_token_done( struct http_request *req ); |
---|
[da2efd4] | 301 | |
---|
[3b878a1] | 302 | struct oauth_info *oauth_request_token( const struct oauth_service *sp, oauth_cb func, void *data ) |
---|
[da2efd4] | 303 | { |
---|
| 304 | struct oauth_info *st = g_new0( struct oauth_info, 1 ); |
---|
[346dfd9] | 305 | GSList *params = NULL; |
---|
[da2efd4] | 306 | |
---|
| 307 | st->func = func; |
---|
| 308 | st->data = data; |
---|
[c2ecadc] | 309 | st->sp = sp; |
---|
[da2efd4] | 310 | |
---|
[346dfd9] | 311 | oauth_params_add( ¶ms, "oauth_callback", "oob" ); |
---|
| 312 | |
---|
[c2ecadc] | 313 | if( !oauth_post_request( sp->url_request_token, ¶ms, oauth_request_token_done, st ) ) |
---|
[18dbb20] | 314 | { |
---|
| 315 | oauth_info_free( st ); |
---|
| 316 | return NULL; |
---|
| 317 | } |
---|
| 318 | |
---|
| 319 | return st; |
---|
[da2efd4] | 320 | } |
---|
| 321 | |
---|
[346dfd9] | 322 | static void oauth_request_token_done( struct http_request *req ) |
---|
[da2efd4] | 323 | { |
---|
| 324 | struct oauth_info *st = req->data; |
---|
| 325 | |
---|
| 326 | st->http = req; |
---|
| 327 | |
---|
| 328 | if( req->status_code == 200 ) |
---|
| 329 | { |
---|
[508c340] | 330 | GSList *params = NULL; |
---|
[da2efd4] | 331 | |
---|
[c2ecadc] | 332 | st->auth_url = g_strdup_printf( "%s?%s", st->sp->url_authorize, req->reply_body ); |
---|
| 333 | oauth_params_parse( ¶ms, req->reply_body ); |
---|
[713d611] | 334 | st->request_token = g_strdup( oauth_params_get( ¶ms, "oauth_token" ) ); |
---|
[da2efd4] | 335 | oauth_params_free( ¶ms ); |
---|
| 336 | } |
---|
| 337 | |
---|
[c42e8b9] | 338 | st->stage = OAUTH_REQUEST_TOKEN; |
---|
[c2ecadc] | 339 | st->func( st ); |
---|
[346dfd9] | 340 | } |
---|
| 341 | |
---|
| 342 | static void oauth_access_token_done( struct http_request *req ); |
---|
| 343 | |
---|
[c2ecadc] | 344 | gboolean oauth_access_token( const char *pin, struct oauth_info *st ) |
---|
[346dfd9] | 345 | { |
---|
| 346 | GSList *params = NULL; |
---|
| 347 | |
---|
[713d611] | 348 | oauth_params_add( ¶ms, "oauth_token", st->request_token ); |
---|
[346dfd9] | 349 | oauth_params_add( ¶ms, "oauth_verifier", pin ); |
---|
| 350 | |
---|
[c2ecadc] | 351 | return oauth_post_request( st->sp->url_access_token, ¶ms, oauth_access_token_done, st ) != NULL; |
---|
[346dfd9] | 352 | } |
---|
| 353 | |
---|
| 354 | static void oauth_access_token_done( struct http_request *req ) |
---|
| 355 | { |
---|
[b2bc25c] | 356 | struct oauth_info *st = req->data; |
---|
| 357 | |
---|
[0bff877] | 358 | st->http = req; |
---|
| 359 | |
---|
[b2bc25c] | 360 | if( req->status_code == 200 ) |
---|
[c42e8b9] | 361 | { |
---|
[93cc86f] | 362 | oauth_params_parse( &st->params, req->reply_body ); |
---|
| 363 | st->token = g_strdup( oauth_params_get( &st->params, "oauth_token" ) ); |
---|
| 364 | st->token_secret = g_strdup( oauth_params_get( &st->params, "oauth_token_secret" ) ); |
---|
[c42e8b9] | 365 | } |
---|
[b2bc25c] | 366 | |
---|
[c42e8b9] | 367 | st->stage = OAUTH_ACCESS_TOKEN; |
---|
[c2ecadc] | 368 | if( st->func( st ) ) |
---|
| 369 | { |
---|
| 370 | /* Don't need these anymore, but keep the rest. */ |
---|
| 371 | g_free( st->auth_url ); |
---|
| 372 | st->auth_url = NULL; |
---|
| 373 | g_free( st->request_token ); |
---|
| 374 | st->request_token = NULL; |
---|
[93cc86f] | 375 | oauth_params_free( &st->params ); |
---|
[c2ecadc] | 376 | } |
---|
[b2bc25c] | 377 | } |
---|
| 378 | |
---|
[c2ecadc] | 379 | char *oauth_http_header( struct oauth_info *oi, const char *method, const char *url, char *args ) |
---|
[b2bc25c] | 380 | { |
---|
[508c340] | 381 | GSList *params = NULL, *l; |
---|
[c2ecadc] | 382 | char *sig = NULL, *params_s, *s; |
---|
[b2bc25c] | 383 | GString *ret = NULL; |
---|
| 384 | |
---|
[c2ecadc] | 385 | oauth_params_add( ¶ms, "oauth_token", oi->token ); |
---|
| 386 | oauth_add_default_params( ¶ms, oi->sp ); |
---|
[b2bc25c] | 387 | |
---|
[18dbb20] | 388 | /* Start building the OAuth header. 'key="value", '... */ |
---|
[b2bc25c] | 389 | ret = g_string_new( "OAuth " ); |
---|
| 390 | for( l = params; l; l = l->next ) |
---|
| 391 | { |
---|
| 392 | char *kv = l->data; |
---|
| 393 | char *eq = strchr( kv, '=' ); |
---|
| 394 | char esc[strlen(kv)*3+1]; |
---|
| 395 | |
---|
| 396 | if( eq == NULL ) |
---|
| 397 | break; /* WTF */ |
---|
| 398 | |
---|
| 399 | strcpy( esc, eq + 1 ); |
---|
| 400 | http_encode( esc ); |
---|
| 401 | |
---|
| 402 | g_string_append_len( ret, kv, eq - kv + 1 ); |
---|
| 403 | g_string_append_c( ret, '"' ); |
---|
| 404 | g_string_append( ret, esc ); |
---|
| 405 | g_string_append( ret, "\", " ); |
---|
| 406 | } |
---|
| 407 | |
---|
[18dbb20] | 408 | /* Now, before generating the signature, add GET/POST arguments to params |
---|
| 409 | since they should be included in the base signature string (but not in |
---|
| 410 | the HTTP header). */ |
---|
[508c340] | 411 | if( args ) |
---|
| 412 | oauth_params_parse( ¶ms, args ); |
---|
| 413 | if( ( s = strchr( url, '?' ) ) ) |
---|
| 414 | { |
---|
| 415 | s = g_strdup( s + 1 ); |
---|
[c2ecadc] | 416 | oauth_params_parse( ¶ms, s ); |
---|
[508c340] | 417 | g_free( s ); |
---|
| 418 | } |
---|
| 419 | |
---|
[18dbb20] | 420 | /* Append the signature and we're done! */ |
---|
[508c340] | 421 | params_s = oauth_params_string( params ); |
---|
[c2ecadc] | 422 | sig = oauth_sign( method, url, params_s, oi ); |
---|
[b2bc25c] | 423 | g_string_append_printf( ret, "oauth_signature=\"%s\"", sig ); |
---|
[ee84bdb] | 424 | g_free( params_s ); |
---|
[b2bc25c] | 425 | |
---|
| 426 | oauth_params_free( ¶ms ); |
---|
| 427 | g_free( sig ); |
---|
| 428 | |
---|
| 429 | return ret ? g_string_free( ret, FALSE ) : NULL; |
---|
[da2efd4] | 430 | } |
---|
[f4b0911] | 431 | |
---|
| 432 | char *oauth_to_string( struct oauth_info *oi ) |
---|
| 433 | { |
---|
| 434 | GSList *params = NULL; |
---|
| 435 | char *ret; |
---|
| 436 | |
---|
| 437 | oauth_params_add( ¶ms, "oauth_token", oi->token ); |
---|
| 438 | oauth_params_add( ¶ms, "oauth_token_secret", oi->token_secret ); |
---|
| 439 | ret = oauth_params_string( params ); |
---|
| 440 | oauth_params_free( ¶ms ); |
---|
| 441 | |
---|
| 442 | return ret; |
---|
| 443 | } |
---|
| 444 | |
---|
[3b878a1] | 445 | struct oauth_info *oauth_from_string( char *in, const struct oauth_service *sp ) |
---|
[f4b0911] | 446 | { |
---|
| 447 | struct oauth_info *oi = g_new0( struct oauth_info, 1 ); |
---|
| 448 | GSList *params = NULL; |
---|
| 449 | |
---|
| 450 | oauth_params_parse( ¶ms, in ); |
---|
| 451 | oi->token = g_strdup( oauth_params_get( ¶ms, "oauth_token" ) ); |
---|
| 452 | oi->token_secret = g_strdup( oauth_params_get( ¶ms, "oauth_token_secret" ) ); |
---|
| 453 | oauth_params_free( ¶ms ); |
---|
| 454 | oi->sp = sp; |
---|
| 455 | |
---|
| 456 | return oi; |
---|
| 457 | } |
---|