diff --git a/skypeweb/skypeweb_login.c b/skypeweb/skypeweb_login.c index 650cd67..188c9ca 100644 --- a/skypeweb/skypeweb_login.c +++ b/skypeweb/skypeweb_login.c @@ -244,12 +244,14 @@ skypeweb_login_got_t(PurpleHttpConnection *http_conn, PurpleHttpResponse *respon } static void -skypeweb_login_got_opid(PurpleHttpConnection *http_conn, PurpleHttpResponse *response, gpointer user_data) +skypeweb_login_got_pprid(PurpleHttpConnection *http_conn, PurpleHttpResponse *response, gpointer user_data) { SkypeWebAccount *sa = user_data; - const gchar *live_login_url = "https://login.live.com" "/ppsecure/post.srf?wa=wsignin1.0&wp=MBI_SSL&wreply=https%3A%2F%2Flw.skype.com%2Flogin%2Foauth%2Fproxy%3Fsite_name%3Dlw.skype.com"; - gchar *ppft; - gchar *opid; + const gchar *proxy_url = "https://lw.skype.com" "/login/oauth/proxy?site_name=lw.skype.com&wa=wsignin1.0"; + gchar *pprid; + gchar *nap; + gchar *anon; + gchar *t; // no witchcraft intended! GString *postdata; PurpleHttpRequest *request; int tmplen; @@ -257,30 +259,22 @@ skypeweb_login_got_opid(PurpleHttpConnection *http_conn, PurpleHttpResponse *res gsize len; data = purple_http_response_get_data(response, &len); - - ppft = skypeweb_string_get_chunk(data, len, ",sFT:'", "',"); - if (!ppft) { - purple_connection_error(sa->pc, PURPLE_CONNECTION_ERROR_AUTHENTICATION_FAILED, _("Failed getting PPFT value, please try logging in via browser first")); - return; - } - opid = skypeweb_string_get_chunk(data, len, "&opid=", "'"); - if (!opid) { - purple_connection_error(sa->pc, PURPLE_CONNECTION_ERROR_AUTHENTICATION_FAILED, _("Failed getting opid value, try using 'Alternate Auth Method' settings")); - return; - } + + SKYPEWEB_GET_HTML_FIELD_NAME_ID(pprid, sa->pc, data, len, "pprid", "pprid"); + SKYPEWEB_GET_HTML_FIELD_NAME_ID(nap, sa->pc, data, len, "NAP", "NAP"); + SKYPEWEB_GET_HTML_FIELD_NAME_ID(anon, sa->pc, data, len, "ANON", "ANON"); + SKYPEWEB_GET_HTML_FIELD_NAME_ID(t, sa->pc, data, len, "t", "t"); + postdata = g_string_new(""); - g_string_append_printf(postdata, "opid=%s&", purple_url_encode(opid)); - g_string_append(postdata, "site_name=lw.skype.com&"); - g_string_append(postdata, "oauthPartner=999&"); - g_string_append(postdata, "client_id=578134&"); - g_string_append(postdata, "redirect_uri=https%3A%2F%2Fweb.skype.com&"); - g_string_append_printf(postdata, "PPFT=%s&", purple_url_encode(ppft)); - g_string_append(postdata, "type=28&"); + g_string_append_printf(postdata, "pprid=%s&", purple_url_encode(pprid)); + g_string_append_printf(postdata, "NAP=%s&", purple_url_encode(nap)); + g_string_append_printf(postdata, "ANON=%s&", purple_url_encode(anon)); + g_string_append_printf(postdata, "t=%s&", purple_url_encode(t)); tmplen = postdata->len; if (postdata->len > INT_MAX) tmplen = INT_MAX; - - request = purple_http_request_new(live_login_url); + + request = purple_http_request_new(proxy_url); purple_http_request_set_method(request, "POST"); purple_http_request_set_cookie_jar(request, sa->cookie_jar); purple_http_request_header_set(request, "Content-Type", "application/x-www-form-urlencoded; charset=UTF-8"); @@ -288,12 +282,13 @@ skypeweb_login_got_opid(PurpleHttpConnection *http_conn, PurpleHttpResponse *res purple_http_request_set_contents(request, postdata->str, tmplen); purple_http_request(sa->pc, request, skypeweb_login_got_t, sa); purple_http_request_unref(request); - + g_string_free(postdata, TRUE); - - g_free(ppft); - g_free(opid); - + g_free(pprid); + g_free(nap); + g_free(anon); + g_free(t); + purple_connection_update_progress(sa->pc, _("Authenticating"), 2, 4); } @@ -340,7 +335,7 @@ skypeweb_login_got_ppft(PurpleHttpConnection *http_conn, PurpleHttpResponse *res purple_http_request_header_set(request, "Content-Type", "application/x-www-form-urlencoded; charset=UTF-8"); purple_http_request_header_set(request, "Accept", "*/*"); purple_http_request_set_contents(request, postdata->str, tmplen); - purple_http_request(sa->pc, request, skypeweb_login_got_opid, sa); + purple_http_request(sa->pc, request, skypeweb_login_got_pprid, sa); purple_http_request_unref(request); g_string_free(postdata, TRUE); diff --git a/skypeweb/skypeweb_util.h b/skypeweb/skypeweb_util.h index 625c3e7..853d718 100644 --- a/skypeweb/skypeweb_util.h +++ b/skypeweb/skypeweb_util.h @@ -33,3 +33,10 @@ PurpleAccount *find_acct(const char *prpl, const char *acct_id); const gchar *skypeweb_user_url_prefix(const gchar *who); const gchar *skypeweb_strip_user_prefix(const gchar *who); + +#define SKYPEWEB_GET_HTML_FIELD_NAME_ID(target, pc, haystack, len, name, id) \ + target = skypeweb_string_get_chunk(haystack, len, "name=\"" name "\" id=\"" id "\" value=\"", "\""); \ + if (!target) { \ + purple_connection_error(pc, PURPLE_CONNECTION_ERROR_AUTHENTICATION_FAILED, _("Failed getting " name " value, please try logging in via browser first")); \ + return; \ + }