23 #include <winpr/string.h>
24 #include <freerdp/log.h>
26 #include "sdl_webview.hpp"
27 #include "webview_impl.hpp"
29 #define TAG CLIENT_TAG("SDL.webview")
31 static BOOL sdl_webview_get_rdsaad_access_token(freerdp* instance,
const char* scope,
32 const char* req_cnf,
char** token)
34 WINPR_ASSERT(instance);
36 WINPR_ASSERT(req_cnf);
39 WINPR_UNUSED(instance);
41 std::string client_id =
"5177bc73-fd99-4c77-a90c-76844c9b6999";
42 std::string redirect_uri =
43 "ms-appx-web%3a%2f%2fMicrosoft.AAD.BrokerPlugin%2f5177bc73-fd99-4c77-a90c-76844c9b6999";
48 "https://login.microsoftonline.com/common/oauth2/v2.0/authorize?client_id=" + client_id +
49 "&response_type=code&scope=" + scope +
"&redirect_uri=" + redirect_uri;
51 const std::string title =
"FreeRDP WebView - AAD access token";
53 auto rc = webview_impl_run(title, url, code);
54 if (!rc || code.empty())
57 auto token_request =
"grant_type=authorization_code&code=" + code +
"&client_id=" + client_id +
58 "&scope=" + scope +
"&redirect_uri=" + redirect_uri +
59 "&req_cnf=" + req_cnf;
60 return client_common_get_access_token(instance, token_request.c_str(), token);
63 static BOOL sdl_webview_get_avd_access_token(freerdp* instance,
char** token)
67 std::string client_id =
"a85cf173-4192-42f8-81fa-777a763e6e2c";
68 std::string redirect_uri =
69 "ms-appx-web%3a%2f%2fMicrosoft.AAD.BrokerPlugin%2fa85cf173-4192-42f8-81fa-777a763e6e2c";
70 std::string scope =
"https%3A%2F%2Fwww.wvd.microsoft.com%2F.default";
75 "https://login.microsoftonline.com/common/oauth2/v2.0/authorize?client_id=" + client_id +
76 "&response_type=code&scope=" + scope +
"&redirect_uri=" + redirect_uri;
77 const std::string title =
"FreeRDP WebView - AVD access token";
79 auto rc = webview_impl_run(title, url, code);
80 if (!rc || code.empty())
83 auto token_request =
"grant_type=authorization_code&code=" + code +
"&client_id=" + client_id +
84 "&scope=" + scope +
"&redirect_uri=" + redirect_uri;
85 return client_common_get_access_token(instance, token_request.c_str(), token);
88 BOOL sdl_webview_get_access_token(freerdp* instance, AccessTokenType tokenType,
char** token,
91 WINPR_ASSERT(instance);
95 case ACCESS_TOKEN_TYPE_AAD:
100 "ACCESS_TOKEN_TYPE_AAD expected 2 additional arguments, but got %" PRIuz
107 "ACCESS_TOKEN_TYPE_AAD expected 2 additional arguments, but got %" PRIuz
112 const char* scope = va_arg(ap,
const char*);
113 const char* req_cnf = va_arg(ap,
const char*);
114 const BOOL rc = sdl_webview_get_rdsaad_access_token(instance, scope, req_cnf, token);
118 case ACCESS_TOKEN_TYPE_AVD:
121 "ACCESS_TOKEN_TYPE_AVD expected 0 additional arguments, but got %" PRIuz
124 return sdl_webview_get_avd_access_token(instance, token);
126 WLog_ERR(TAG,
"Unexpected value for AccessTokenType [%" PRIuz
"], aborting", tokenType);