From e1412d0ae8cbf88867cff1bf0d1510c9fa01bafb Mon Sep 17 00:00:00 2001 From: eionrobb Date: Tue, 14 Jan 2014 05:02:57 +0000 Subject: Handle expired login access_token's with an error callback during login --- steam-mobile/libsteam.c | 36 +++++++++++++++++++++++++++++------- 1 file changed, 29 insertions(+), 7 deletions(-) diff --git a/steam-mobile/libsteam.c b/steam-mobile/libsteam.c index c86613b..ff0bf37 100644 --- a/steam-mobile/libsteam.c +++ b/steam-mobile/libsteam.c @@ -148,6 +148,7 @@ steam_accountid_to_steamid(gint64 accountid) static void steam_fetch_new_sessionid(SteamAccount *sa); static void steam_get_friend_summaries(SteamAccount *sa, const gchar *who); +static void steam_get_rsa_key(SteamAccount *sa); static void steam_friend_action(SteamAccount *sa, const gchar *who, const gchar *action) @@ -918,15 +919,30 @@ steam_login_access_token_cb(SteamAccount *sa, JsonObject *obj, gpointer user_dat steam_fetch_new_sessionid(sa); } +static void +steam_login_with_access_token_error_cb(SteamAccount *sa, const gchar *data, gssize data_len, gpointer user_data) +{ + if (g_strstr_len(data, data_len, "401 Unauthorized")) { + // Our access_token looks like it expired? + //Wipe it and try re-auth + + steam_account_set_access_token(sa, NULL); + steam_get_rsa_key(sa); + } +} + static void steam_login_with_access_token(SteamAccount *sa) { gchar *postdata; + SteamConnection *sconn; postdata = g_strdup_printf("access_token=%s", purple_url_encode(steam_account_get_access_token(sa))); //TODO, handle a 401 response from the server - trash the steamguard and access_token - steam_post_or_get(sa, STEAM_METHOD_POST | STEAM_METHOD_SSL, NULL, "/ISteamWebUserPresenceOAuth/Logon/v0001", postdata, steam_login_access_token_cb, NULL, TRUE); + sconn = steam_post_or_get(sa, STEAM_METHOD_POST | STEAM_METHOD_SSL, NULL, "/ISteamWebUserPresenceOAuth/Logon/v0001", postdata, steam_login_access_token_cb, NULL, TRUE); g_free(postdata); + + sconn->error_callback = steam_login_with_access_token_error_cb; } static void @@ -1035,6 +1051,16 @@ steam_login_got_rsakey(SteamAccount *sa, JsonObject *obj, gpointer user_data) g_free(encrypted_password); } +static void +steam_get_rsa_key(SteamAccount *sa) +{ + gchar *url; + + url = g_strdup_printf("/mobilelogin/getrsakey?username=%s", purple_url_encode(sa->account->username)); + steam_post_or_get(sa, STEAM_METHOD_GET | STEAM_METHOD_SSL, "steamcommunity.com", url, NULL, steam_login_got_rsakey, NULL, TRUE); + g_free(url); +} + #ifdef G_OS_UNIX static void steam_keyring_got_password(GnomeKeyringResult res, const gchar* access_token, gpointer user_data) { @@ -1047,9 +1073,7 @@ steam_keyring_got_password(GnomeKeyringResult res, const gchar* access_token, gp steam_login_with_access_token(sa); } else { - gchar *url = g_strdup_printf("/mobilelogin/getrsakey?username=%s", purple_url_encode(sa->account->username)); - steam_post_or_get(sa, STEAM_METHOD_GET | STEAM_METHOD_SSL, "steamcommunity.com", url, NULL, steam_login_got_rsakey, NULL, TRUE); - g_free(url); + steam_get_rsa_key(sa); } } #endif @@ -1092,9 +1116,7 @@ steam_login(PurpleAccount *account) steam_login_with_access_token(sa); } else { - gchar *url = g_strdup_printf("/mobilelogin/getrsakey?username=%s", purple_url_encode(account->username)); - steam_post_or_get(sa, STEAM_METHOD_GET | STEAM_METHOD_SSL, "steamcommunity.com", url, NULL, steam_login_got_rsakey, NULL, TRUE); - g_free(url); + steam_get_rsa_key(sa); } purple_connection_set_state(pc, PURPLE_CONNECTING); -- cgit v1.2.3