diff options
author | aunsane <aunsane@gmail.com> | 2017-03-11 13:07:25 +0300 |
---|---|---|
committer | aunsane <aunsane@gmail.com> | 2017-03-11 13:07:52 +0300 |
commit | 160ecb9f0607c52809201be769cb5739a8b39836 (patch) | |
tree | 5efbd2727519ffccac23c797e99dab46a2e99ef6 /protocols/SkypeWeb/src/skype_oauth.cpp | |
parent | e02f1e05b363226a48fe9a4b151748a5cbb295d9 (diff) |
SkypeWeb: add new oauth login flow (should fix auth with ms accounts)
Diffstat (limited to 'protocols/SkypeWeb/src/skype_oauth.cpp')
-rw-r--r-- | protocols/SkypeWeb/src/skype_oauth.cpp | 120 |
1 files changed, 120 insertions, 0 deletions
diff --git a/protocols/SkypeWeb/src/skype_oauth.cpp b/protocols/SkypeWeb/src/skype_oauth.cpp new file mode 100644 index 0000000000..9926402232 --- /dev/null +++ b/protocols/SkypeWeb/src/skype_oauth.cpp @@ -0,0 +1,120 @@ +/* +Copyright (c) 2015-17 Miranda NG project (http://miranda-ng.org) + +This program is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License +as published by the Free Software Foundation version 2 +of the License. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see <http://www.gnu.org/licenses/>. +*/ + +#include "stdafx.h" + +void CSkypeProto::OnOAuthStart(const NETLIBHTTPREQUEST *response) +{ + if (response == NULL || response->pData == NULL) + { + ProtoBroadcastAck(NULL, ACKTYPE_LOGIN, ACKRESULT_FAILED, NULL, LOGIN_ERROR_UNKNOWN); + SetStatus(ID_STATUS_OFFLINE); + return; + } + + std::regex regex; + std::smatch match; + std::map<std::string, std::string> scookies; + std::string content = response->pData; + + regex = "<input type=\"hidden\" name=\"PPFT\" id=\"i0327\" value=\"(.+?)\"/>"; + + if (!std::regex_search(content, match, regex)) + { + ProtoBroadcastAck(NULL, ACKTYPE_LOGIN, ACKRESULT_FAILED, NULL, LOGIN_ERROR_UNKNOWN); + SetStatus(ID_STATUS_OFFLINE); + return; + } + std::string PPTF = match[1]; + + for (int i = 0; i < response->headersCount; i++) + { + if (mir_strcmpi(response->headers[i].szName, "Set-Cookie")) + continue; + + regex = "^(.+?)=(.+?);"; + content = response->headers[i].szValue; + if (std::regex_search(content, match, regex)) + scookies[match[1]] = match[2]; + } + + ptrA login(getStringA(SKYPE_SETTINGS_ID)); + ptrA password(getStringA(SKYPE_SETTINGS_PASSWORD)); + CMStringA mscookies(FORMAT, "MSPRequ=%s;MSPOK=%s;CkTst=G%lld;", scookies["MSPRequ"].c_str(), scookies["MSPOK"].c_str(), time(NULL)); + + PushRequest(new OAuthRequest(login, password, mscookies.c_str(), PPTF.c_str()), &CSkypeProto::OnOAuthAuthorize); +} + +void CSkypeProto::OnOAuthAuthorize(const NETLIBHTTPREQUEST *response) +{ + if (response == NULL || response->pData == NULL) + { + ProtoBroadcastAck(NULL, ACKTYPE_LOGIN, ACKRESULT_FAILED, NULL, LOGIN_ERROR_UNKNOWN); + SetStatus(ID_STATUS_OFFLINE); + return; + } + + std::regex regex; + std::smatch match; + std::string content = response->pData; + ptrA szContent(response->pData); + + regex = "<input type=\"hidden\" name=\"t\" id=\"t\" value=\"(.+?)\">"; + if (!std::regex_search(content, match, regex)) + { + ProtoBroadcastAck(NULL, ACKTYPE_LOGIN, ACKRESULT_FAILED, NULL, LOGIN_ERROR_UNKNOWN); + SetStatus(ID_STATUS_OFFLINE); + return; + } + std::string t = match[1]; + + PushRequest(new OAuthRequest(t.c_str()), &CSkypeProto::OnOAuthEnd); +} + +void CSkypeProto::OnOAuthEnd(const NETLIBHTTPREQUEST *response) +{ + if (response == NULL || response->pData == NULL) + { + ProtoBroadcastAck(NULL, ACKTYPE_LOGIN, ACKRESULT_FAILED, NULL, LOGIN_ERROR_UNKNOWN); + SetStatus(ID_STATUS_OFFLINE); + return; + } + + std::regex regex; + std::smatch match; + std::string content = response->pData; + + regex = "<input type=\"hidden\" name=\"skypetoken\" value=\"(.+?)\"/>"; + if (!std::regex_search(content, match, regex)) + { + ProtoBroadcastAck(NULL, ACKTYPE_LOGIN, ACKRESULT_FAILED, NULL, LOGIN_ERROR_UNKNOWN); + SetStatus(ID_STATUS_OFFLINE); + return; + } + std::string token = match[1]; + setString("TokenSecret", token.c_str()); + regex = "<input type=\"hidden\" name=\"expires_in\" value=\"(.+?)\"/>"; + + if (std::regex_search(content, match, regex)) + { + std::string expiresIn = match[1]; + int seconds = atoi(expiresIn.c_str()); + setDword("TokenExpiresIn", time(NULL) + seconds); + } + + OnLoginSuccess(); +}
\ No newline at end of file |