summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--protocols/Teams/src/proto.h5
-rw-r--r--protocols/Teams/src/teams_http.cpp8
-rw-r--r--protocols/Teams/src/teams_login.cpp57
3 files changed, 58 insertions, 12 deletions
diff --git a/protocols/Teams/src/proto.h b/protocols/Teams/src/proto.h
index a29b1a2a4e..78a57f422f 100644
--- a/protocols/Teams/src/proto.h
+++ b/protocols/Teams/src/proto.h
@@ -3,6 +3,7 @@
enum HostType {
HOST_OTHER = 0,
HOST_LOGIN = 1,
+ HOST_TEAMS = 2,
};
struct AsyncHttpRequest : public MTHttpRequest<CTeamsProto>
@@ -42,7 +43,7 @@ class CTeamsProto : public PROTO<CTeamsProto>
LIST<AsyncHttpRequest> m_requests;
MEventHandle m_hRequestQueueEvent;
HANDLE m_hRequestQueueThread;
- CMStringA m_szAccessToken, m_szSubstrateToken;
+ CMStringA m_szAccessToken, m_szSubstrateToken, m_szSkypeToken;
void __cdecl WorkerThread(void *);
@@ -67,9 +68,11 @@ class CTeamsProto : public PROTO<CTeamsProto>
void OauthRefreshServices();
void RefreshToken(const char *pszScope, AsyncHttpRequest::MTHttpRequestHandler pFunc);
+ void OnReceiveSkypeToken(MHttpResponse *response, AsyncHttpRequest *pRequest);
void OnReceiveDevicePoll(MHttpResponse *response, AsyncHttpRequest *pRequest);
void OnReceiveDeviceToken(MHttpResponse *response, AsyncHttpRequest *pRequest);
void OnRefreshAccessToken(MHttpResponse *response, AsyncHttpRequest *pRequest);
+ void OnRefreshSkypeToken(MHttpResponse *response, AsyncHttpRequest *pRequest);
void OnRefreshSubstrate(MHttpResponse *response, AsyncHttpRequest *pRequest);
// options
diff --git a/protocols/Teams/src/teams_http.cpp b/protocols/Teams/src/teams_http.cpp
index 67bbd78bd4..ecce58fa92 100644
--- a/protocols/Teams/src/teams_http.cpp
+++ b/protocols/Teams/src/teams_http.cpp
@@ -22,6 +22,7 @@ AsyncHttpRequest::AsyncHttpRequest(int type, HostType host, LPCSTR url, MTHttpRe
{
switch (host) {
case HOST_LOGIN: m_szUrl = "login.microsoftonline.com"; break;
+ case HOST_TEAMS: m_szUrl = "teams.live.com"; break;
}
AddHeader("User-Agent", NETLIB_USER_AGENT);
@@ -68,6 +69,13 @@ void CTeamsProto::PushRequest(AsyncHttpRequest *request)
{
if (m_isTerminated)
return;
+
+ if (request->m_host == HOST_TEAMS) {
+ if (!request->FindHeader("Authorization"))
+ request->AddHeader("Authorization", "Bearer " + m_szAccessToken);
+ request->AddHeader("Accept", "application/json");
+ }
+
{
mir_cslock lock(m_requestQueueLock);
m_requests.insert(request);
diff --git a/protocols/Teams/src/teams_login.cpp b/protocols/Teams/src/teams_login.cpp
index cbfdc59d12..90302a3461 100644
--- a/protocols/Teams/src/teams_login.cpp
+++ b/protocols/Teams/src/teams_login.cpp
@@ -18,7 +18,10 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "stdafx.h"
#define TEAMS_OAUTH_RESOURCE "https://api.spaces.skype.com"
+#define TEAMS_OAUTH_SCOPE "service::api.fl.teams.microsoft.com::MBI_SSL"
+#define TEAMS_SKYPETOKEN_SCOPE "service::api.fl.spaces.skype.com::MBI_SSL"
#define TEAMS_PERSONAL_TENANT_ID "9188040d-6c67-4c5b-b112-36a304b66dad"
+#define SCOPE_SUFFIX " openid profile offline_access"
void CTeamsProto::LoginError()
{
@@ -56,7 +59,6 @@ void CTeamsProto::OnReceiveDevicePoll(MHttpResponse *response, AsyncHttpRequest*
m_szDeviceCode.Empty();
auto &root = reply.data();
- m_szAccessToken = root["access_token"].as_mstring();
setWString("RefreshToken", root["refresh_token"].as_mstring());
OauthRefreshServices();
@@ -140,15 +142,21 @@ void CTeamsProto::OnReceiveDeviceToken(MHttpResponse *response, AsyncHttpRequest
/////////////////////////////////////////////////////////////////////////////////////////
-void CTeamsProto::RefreshToken(const char *pszScope, AsyncHttpRequest::MTHttpRequestHandler pFunc)
+void CTeamsProto::OnReceiveSkypeToken(MHttpResponse *response, AsyncHttpRequest*)
{
- auto *pReq = new AsyncHttpRequest(REQUEST_POST, HOST_LOGIN, "/" TEAMS_PERSONAL_TENANT_ID "/oauth2/v2.0/token", pFunc);
- pReq << CHAR_PARAM("scope", pszScope) << CHAR_PARAM("client_id", TEAMS_CLIENT_ID)
- << CHAR_PARAM("grant_type", "refresh_token") << CHAR_PARAM("refresh_token", getMStringA("RefreshToken"));
- PushRequest(pReq);
+ JsonReply reply(response);
+ if (!reply) {
+ LoginError();
+ return;
+ }
+
+ auto &root = reply.data();
+ m_szSkypeToken = root["skypeToken"]["skypetoken"].as_mstring();
+
+ LoggedIn();
}
-void CTeamsProto::OnRefreshAccessToken(MHttpResponse *response, AsyncHttpRequest *pRequest)
+void CTeamsProto::OnRefreshAccessToken(MHttpResponse *response, AsyncHttpRequest*)
{
JsonReply reply(response);
if (!reply) {
@@ -163,7 +171,23 @@ void CTeamsProto::OnRefreshAccessToken(MHttpResponse *response, AsyncHttpRequest
LoggedIn();
}
-void CTeamsProto::OnRefreshSubstrate(MHttpResponse *response, AsyncHttpRequest *pRequest)
+void CTeamsProto::OnRefreshSkypeToken(MHttpResponse *response, AsyncHttpRequest *)
+{
+ JsonReply reply(response);
+ if (!reply) {
+ LoginError();
+ return;
+ }
+
+ auto &root = reply.data();
+ CMStringA szAccessToken(root["access_token"].as_mstring());
+
+ auto *pReq = new AsyncHttpRequest(REQUEST_POST, HOST_TEAMS, "/api/auth/v1.0/authz/consumer", &CTeamsProto::OnReceiveSkypeToken);
+ pReq->AddHeader("Authorization", "Bearer " + szAccessToken);
+ PushRequest(pReq);
+}
+
+void CTeamsProto::OnRefreshSubstrate(MHttpResponse *response, AsyncHttpRequest*)
{
JsonReply reply(response);
if (!reply) {
@@ -175,10 +199,18 @@ void CTeamsProto::OnRefreshSubstrate(MHttpResponse *response, AsyncHttpRequest *
m_szSubstrateToken = root["access_token"].as_mstring();
}
+void CTeamsProto::RefreshToken(const char *pszScope, AsyncHttpRequest::MTHttpRequestHandler pFunc)
+{
+ auto *pReq = new AsyncHttpRequest(REQUEST_POST, HOST_LOGIN, "/" TEAMS_PERSONAL_TENANT_ID "/oauth2/v2.0/token", pFunc);
+ pReq << CHAR_PARAM("scope", pszScope) << CHAR_PARAM("client_id", TEAMS_CLIENT_ID)
+ << CHAR_PARAM("grant_type", "refresh_token") << CHAR_PARAM("refresh_token", getMStringA("RefreshToken"));
+ PushRequest(pReq);
+}
+
void CTeamsProto::OauthRefreshServices()
{
- RefreshToken("service::api.fl.teams.microsoft.com::MBI_SSL openid profile offline_access", &CTeamsProto::OnRefreshAccessToken);
- RefreshToken("https://substrate.office.com/M365.Access openid profile offline_access", &CTeamsProto::OnRefreshSubstrate);
+ RefreshToken(TEAMS_SKYPETOKEN_SCOPE SCOPE_SUFFIX, &CTeamsProto::OnRefreshSkypeToken);
+ RefreshToken("https://substrate.office.com/M365.Access" SCOPE_SUFFIX, &CTeamsProto::OnRefreshSubstrate);
}
/////////////////////////////////////////////////////////////////////////////////////////
@@ -205,5 +237,8 @@ void CTeamsProto::Login()
pReq << CHAR_PARAM("client_id", TEAMS_CLIENT_ID) << CHAR_PARAM("resource", TEAMS_OAUTH_RESOURCE);
PushRequest(pReq);
}
- else OauthRefreshServices();
+ else {
+ RefreshToken(TEAMS_OAUTH_SCOPE SCOPE_SUFFIX, &CTeamsProto::OnRefreshAccessToken);
+ OauthRefreshServices();
+ }
}