Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace 2nd post.srf with oauth/proxy request #664

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 25 additions & 30 deletions skypeweb/skypeweb_login.c
Original file line number Diff line number Diff line change
Expand Up @@ -244,56 +244,51 @@ 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;
const gchar *data;
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");
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_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);
}

Expand Down Expand Up @@ -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);
Expand Down
7 changes: 7 additions & 0 deletions skypeweb/skypeweb_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -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; \
}