aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWilmer van der Gaast <wilmer@gaast.net>2011-12-19 13:54:49 +0100
committerWilmer van der Gaast <wilmer@gaast.net>2011-12-19 13:54:49 +0100
commit36533bf6bfc01f56afd6a8cd7bd3dfa9de87297b (patch)
tree88d6198cba41269ff74c59dda317e2a559d5236e
parent4be0e3458a001a1c2eb3dd0074d7fd65260f2e6f (diff)
When updating the XMPP password field with OAuth data, try harder to preserve
existing data. (Like refresh tokens which we'll need again on next login.)
-rw-r--r--lib/oauth.h1
-rw-r--r--protocols/jabber/sasl.c24
2 files changed, 12 insertions, 13 deletions
diff --git a/lib/oauth.h b/lib/oauth.h
index b7388503..50adc95c 100644
--- a/lib/oauth.h
+++ b/lib/oauth.h
@@ -95,4 +95,5 @@ void oauth_params_add( GSList **params, const char *key, const char *value );
void oauth_params_parse( GSList **params, char *in );
void oauth_params_free( GSList **params );
char *oauth_params_string( GSList *params );
+void oauth_params_set( GSList **params, const char *key, const char *value );
const char *oauth_params_get( GSList **params, const char *key );
diff --git a/protocols/jabber/sasl.c b/protocols/jabber/sasl.c
index 8727212f..06dda8a8 100644
--- a/protocols/jabber/sasl.c
+++ b/protocols/jabber/sasl.c
@@ -527,6 +527,7 @@ static void sasl_oauth2_got_token( gpointer data, const char *access_token, cons
{
struct im_connection *ic = data;
struct jabber_data *jd;
+ GSList *auth = NULL;
if( g_slist_find( jabber_connections, ic ) == NULL )
return;
@@ -539,19 +540,16 @@ static void sasl_oauth2_got_token( gpointer data, const char *access_token, cons
imc_logout( ic, TRUE );
return;
}
- if( refresh_token != NULL )
- {
- g_free( ic->acc->pass );
- ic->acc->pass = g_strdup_printf( "refresh_token=%s", refresh_token );
- }
- /* Should do this, but only in the Facebook case where we get an access
- token that never expires. Shouldn't overwrite a refresh token with
- an access token.
- else
- {
- g_free( ic->acc->pass );
- ic->acc->pass = g_strdup_printf( "access_token=%s", access_token );
- } */
+
+ oauth_params_parse( &auth, ic->acc->pass );
+ if( refresh_token )
+ oauth_params_set( &auth, "refresh_token", refresh_token );
+ if( access_token )
+ oauth_params_set( &auth, "access_token", access_token );
+
+ g_free( ic->acc->pass );
+ ic->acc->pass = oauth_params_string( auth );
+ oauth_params_free( &auth );
g_free( jd->oauth2_access_token );
jd->oauth2_access_token = g_strdup( access_token );