diff options
| author | George Hazan <george.hazan@gmail.com> | 2025-06-13 11:52:06 +0300 |
|---|---|---|
| committer | George Hazan <george.hazan@gmail.com> | 2025-06-13 11:52:06 +0300 |
| commit | a653b4ad9217a45aad65a7eec71234e652acd446 (patch) | |
| tree | 4d3df40b4a9a8e477f2aafbf8470c51cea7c4b4c /protocols | |
| parent | 1392edb8f6a78838fcbff17f925ad077f4ede38d (diff) | |
fixes #5046 (MsTeams: Will not login)
Diffstat (limited to 'protocols')
| -rw-r--r-- | protocols/Teams/Teams.vcxproj | 1 | ||||
| -rw-r--r-- | protocols/Teams/Teams.vcxproj.filters | 3 | ||||
| -rw-r--r-- | protocols/Teams/src/stdafx.h | 1 | ||||
| -rw-r--r-- | protocols/Teams/src/teams_endpoint.cpp | 81 | ||||
| -rw-r--r-- | protocols/Teams/src/teams_http.cpp | 6 | ||||
| -rw-r--r-- | protocols/Teams/src/teams_login.cpp | 16 | ||||
| -rw-r--r-- | protocols/Teams/src/teams_proto.cpp | 7 | ||||
| -rw-r--r-- | protocols/Teams/src/teams_proto.h | 7 | ||||
| -rw-r--r-- | protocols/Teams/src/teams_server.cpp | 52 |
9 files changed, 21 insertions, 153 deletions
diff --git a/protocols/Teams/Teams.vcxproj b/protocols/Teams/Teams.vcxproj index 844f6d0ffe..201576d268 100644 --- a/protocols/Teams/Teams.vcxproj +++ b/protocols/Teams/Teams.vcxproj @@ -33,7 +33,6 @@ <ClCompile Include="src\teams_avatars.cpp" /> <ClCompile Include="src\teams_chatrooms.cpp" /> <ClCompile Include="src\teams_contacts.cpp" /> - <ClCompile Include="src\teams_endpoint.cpp" /> <ClCompile Include="src\teams_files.cpp" /> <ClCompile Include="src\teams_history.cpp" /> <ClCompile Include="src\teams_http.cpp" /> diff --git a/protocols/Teams/Teams.vcxproj.filters b/protocols/Teams/Teams.vcxproj.filters index 98d55c54ab..2e6b7466b3 100644 --- a/protocols/Teams/Teams.vcxproj.filters +++ b/protocols/Teams/Teams.vcxproj.filters @@ -49,9 +49,6 @@ <ClCompile Include="src\teams_utils.cpp"> <Filter>Source Files</Filter> </ClCompile> - <ClCompile Include="src\teams_endpoint.cpp"> - <Filter>Source Files</Filter> - </ClCompile> <ClCompile Include="src\teams_search.cpp"> <Filter>Source Files</Filter> </ClCompile> diff --git a/protocols/Teams/src/stdafx.h b/protocols/Teams/src/stdafx.h index 1e7c333898..773a42ef50 100644 --- a/protocols/Teams/src/stdafx.h +++ b/protocols/Teams/src/stdafx.h @@ -85,7 +85,6 @@ struct AsyncHttpRequest : public MTHttpRequest<CTeamsProto> AsyncHttpRequest(int type, SkypeHost host, LPCSTR url = nullptr, MTHttpRequestHandler pFunc = nullptr); void AddAuthentication(CTeamsProto *ppro); - void AddRegistration(CTeamsProto *ppro); }; #include "teams_proto.h" diff --git a/protocols/Teams/src/teams_endpoint.cpp b/protocols/Teams/src/teams_endpoint.cpp deleted file mode 100644 index b84494f8bd..0000000000 --- a/protocols/Teams/src/teams_endpoint.cpp +++ /dev/null @@ -1,81 +0,0 @@ -/* -Copyright (c) 2025 Miranda NG team (https://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 CTeamsProto::SendCreateEndpoint() -{ - auto *pReq = new AsyncHttpRequest(REQUEST_POST, HOST_DEFAULT, "/users/ME/endpoints", &CTeamsProto::OnEndpointCreated); - pReq->flags |= NLHRF_REDIRECT; - pReq->m_szParam = "{\"endpointFeatures\":\"Agent,Presence2015,MessageProperties,CustomUserProperties,Casts,ModernBots,AutoIdleForWebApi,secureThreads,notificationStream,InviteFree,SupportsReadReceipts,ued\"}"; - pReq->AddHeader("Origin", "https://web.skype.com"); - pReq->AddHeader("Referer", "https://web.skype.com/"); - pReq->AddAuthentication(this); - - PushRequest(pReq); -} - -void CTeamsProto::OnEndpointCreated(MHttpResponse *response, AsyncHttpRequest*) -{ - if (IsStatusConnecting(m_iStatus)) - m_iStatus++; - - if (response == nullptr) { - debugLogA(__FUNCTION__ ": failed to get create endpoint"); - ProtoBroadcastAck(NULL, ACKTYPE_LOGIN, ACKRESULT_FAILED, NULL, 1001); - SetStatus(ID_STATUS_OFFLINE); - return; - } - - switch (response->resultCode) { - case 200: - case 201: // okay, endpoint created - break; - - case 401: // unauthorized - default: - delSetting("TokenExpiresIn"); - ProtoBroadcastAck(NULL, ACKTYPE_LOGIN, ACKRESULT_FAILED, NULL, 1001); - SetStatus(ID_STATUS_OFFLINE); - return; - } - - // Succeeded, decode the answer - if (auto *hdr = response->FindHeader("Set-RegistrationToken")) { - CMStringA szValue = hdr; - int iStart = 0; - while (true) { - CMStringA szToken = szValue.Tokenize(";", iStart).Trim(); - if (iStart == -1) - break; - - int iStart2 = 0; - CMStringA name = szToken.Tokenize("=", iStart2); - CMStringA val = szToken.Mid(iStart2); - - if (name == "registrationToken") - m_szRegToken = val; - else if (name == "endpointId") { - val.Replace("{", ""); - val.Replace("}", ""); - m_szEndpoint = val; - } - } - } - - LoggedIn(); -} diff --git a/protocols/Teams/src/teams_http.cpp b/protocols/Teams/src/teams_http.cpp index 66562ab2a0..422087d15a 100644 --- a/protocols/Teams/src/teams_http.cpp +++ b/protocols/Teams/src/teams_http.cpp @@ -55,11 +55,6 @@ void AsyncHttpRequest::AddAuthentication(CTeamsProto *ppro) AddHeader("Authentication", CMStringA("skypetoken=") + ppro->m_szSkypeToken); } -void AsyncHttpRequest::AddRegistration(CTeamsProto *ppro) -{ - AddHeader("RegistrationToken", "registrationToken=" + ppro->m_szRegToken); -} - ///////////////////////////////////////////////////////////////////////////////////////// void CTeamsProto::StartQueue() @@ -144,7 +139,6 @@ MHttpResponse* CTeamsProto::DoSend(AsyncHttpRequest *pReq) case HOST_CHATS: pReq->AddAuthentication(this); - pReq->AddRegistration(this); pReq->AddHeader("Accept", "application/json"); break; diff --git a/protocols/Teams/src/teams_login.cpp b/protocols/Teams/src/teams_login.cpp index 4d494276b2..b676af3641 100644 --- a/protocols/Teams/src/teams_login.cpp +++ b/protocols/Teams/src/teams_login.cpp @@ -41,7 +41,15 @@ void CTeamsProto::LoggedIn() ProtoBroadcastAck(0, ACKTYPE_STATUS, ACKRESULT_SUCCESS, (HANDLE)oldStatus, m_iStatus); SetServerStatus(m_iStatus); - SendPresence(); + + ReceiveAvatar(0); + RefreshContactsInfo(); + RefreshConversations(); + + GetProfileInfo(0); + + PushRequest(new AsyncHttpRequest(REQUEST_POST, HOST_TEAMS_API, "/imageauth/cookie", &CTeamsProto::OnReceiveApiCookie)); + StartTrouter(); } @@ -156,9 +164,11 @@ void CTeamsProto::OnReceiveSkypeToken(MHttpResponse *response, AsyncHttpRequest auto &token = reply.data()["skypeToken"]; m_szSkypeToken = token["skypetoken"].as_mstring(); - setWString(DBKEY_ID, token["skypeid"].as_mstring()); - SendCreateEndpoint(); + m_szOwnSkypeId = token["skypeid"].as_mstring(); + setString(DBKEY_ID, m_szOwnSkypeId); + + LoggedIn(); } void CTeamsProto::OnRefreshAccessToken(MHttpResponse *response, AsyncHttpRequest *) diff --git a/protocols/Teams/src/teams_proto.cpp b/protocols/Teams/src/teams_proto.cpp index 842acdfc2c..a9462bec8d 100644 --- a/protocols/Teams/src/teams_proto.cpp +++ b/protocols/Teams/src/teams_proto.cpp @@ -32,6 +32,13 @@ CTeamsProto::CTeamsProto(const char *protoName, const wchar_t *userName) : m_wstrMoodEmoji(this, "MoodEmoji", L""), m_wstrMoodMessage(this, "XStatusMsg", L"") { + // create endpoint + m_szEndpoint = getMStringA("Endpoint"); + if (m_szEndpoint.IsEmpty()) { + m_szEndpoint = Utils_GenerateUUID(); + setString("Endpoint", m_szEndpoint); + } + // network NETLIBUSER nlu = {}; nlu.flags = NUF_OUTGOING | NUF_INCOMING | NUF_HTTPCONNS | NUF_UNICODE; diff --git a/protocols/Teams/src/teams_proto.h b/protocols/Teams/src/teams_proto.h index 2b6ad246d8..f6a9ea7e58 100644 --- a/protocols/Teams/src/teams_proto.h +++ b/protocols/Teams/src/teams_proto.h @@ -130,8 +130,7 @@ public: // other data int m_iPollingId, m_iMessageId = 1; - ptrA m_szOwnSkypeId; - CMStringA m_szSkypename, m_szMyname, m_szRegToken, m_szSkypeToken, m_szEndpoint, m_szApiCookie; + CMStringA m_szSkypename, m_szMyname, m_szOwnSkypeId, m_szSkypeToken, m_szEndpoint, m_szApiCookie; MCONTACT m_hMyContact; __forceinline CMStringA getId(MCONTACT hContact) { @@ -258,10 +257,6 @@ private: void OnEndpointCreated(MHttpResponse *response, AsyncHttpRequest *pRequest); void OnReceiveApiCookie(MHttpResponse *response, AsyncHttpRequest *pRequest); - void OnCapabilitiesSended(MHttpResponse *response, AsyncHttpRequest *pRequest); - - void SendCreateEndpoint(); - void SendPresence(); void OauthRefreshServices(); void RefreshToken(const char *pszScope, AsyncHttpRequest::MTHttpRequestHandler pFunc); diff --git a/protocols/Teams/src/teams_server.cpp b/protocols/Teams/src/teams_server.cpp index fd3cd3f6cb..3345e1f265 100644 --- a/protocols/Teams/src/teams_server.cpp +++ b/protocols/Teams/src/teams_server.cpp @@ -30,58 +30,6 @@ void CTeamsProto::OnReceiveApiCookie(MHttpResponse *response, AsyncHttpRequest * m_szApiCookie = response->GetCookies(); } -void CTeamsProto::OnCapabilitiesSended(MHttpResponse *response, AsyncHttpRequest *) -{ - if (response == nullptr || response->body.IsEmpty()) { - ProtoBroadcastAck(NULL, ACKTYPE_LOGIN, ACKRESULT_FAILED, NULL, 1001); - SetStatus(ID_STATUS_OFFLINE); - return; - } - - ReceiveAvatar(0); - RefreshContactsInfo(); - RefreshConversations(); - - JSONNode root = JSONNode::parse(response->body); - if (root) - m_szOwnSkypeId = UrlToSkypeId(root["selfLink"].as_string().c_str()).Detach(); - - GetProfileInfo(0); - - PushRequest(new AsyncHttpRequest(REQUEST_POST, HOST_TEAMS_API, "/imageauth/cookie", &CTeamsProto::OnReceiveApiCookie)); -} - -void CTeamsProto::SendPresence() -{ - ptrA epname; - - if (!m_bUseHostnameAsPlace && m_wstrPlace && *m_wstrPlace) - epname = mir_utf8encodeW(m_wstrPlace); - else { - wchar_t compName[MAX_COMPUTERNAME_LENGTH + 1]; - DWORD size = _countof(compName); - GetComputerNameW(compName, &size); - epname = mir_utf8encodeW(compName); - } - - JSONNode privateInfo; privateInfo.set_name("privateInfo"); - privateInfo << CHAR_PARAM("epname", epname); - - JSONNode publicInfo; publicInfo.set_name("publicInfo"); - publicInfo << CHAR_PARAM("capabilities", "Audio|Video") << INT_PARAM("typ", 125) - << CHAR_PARAM("skypeNameVersion", "Miranda NG Skype") << CHAR_PARAM("nodeInfo", "xx") << CHAR_PARAM("version", g_szMirVer); - - JSONNode node; - node << CHAR_PARAM("id", "messagingService") << CHAR_PARAM("type", "EndpointPresenceDoc") - << CHAR_PARAM("selfLink", "uri") << privateInfo << publicInfo; - - auto *pReq = new AsyncHttpRequest(REQUEST_PUT, HOST_DEFAULT, "/users/ME/endpoints/" + mir_urlEncode(m_szEndpoint) + "/presenceDocs/messagingService", - &CTeamsProto::OnCapabilitiesSended); - pReq->m_szParam = node.write().c_str(); - pReq->AddRegistration(this); - PushRequest(pReq); -} - ///////////////////////////////////////////////////////////////////////////////////////// void CTeamsProto::OnStatusChanged(MHttpResponse *response, AsyncHttpRequest *) |
