23 #include <winpr/string.h>
24 #include <freerdp/log.h>
25 #include <freerdp/utils/aad.h>
27 #include "sdl_webview.hpp"
28 #include "webview_impl.hpp"
30 #define TAG CLIENT_TAG("SDL.webview")
32 static std::string from_settings(
const rdpSettings* settings, FreeRDP_Settings_Keys_String
id)
43 static std::string from_aad_wellknown(rdpContext* context, AAD_WELLKNOWN_VALUES which)
45 auto val = freerdp_utils_aad_get_wellknown_string(context, which);
49 WLog_WARN(TAG,
"[wellknown] key %s is NULL", freerdp_utils_aad_wellknwon_value_name(which));
55 static BOOL sdl_webview_get_rdsaad_access_token(freerdp* instance,
const char* scope,
56 const char* req_cnf,
char** token)
58 WINPR_ASSERT(instance);
60 WINPR_ASSERT(req_cnf);
63 WINPR_UNUSED(instance);
64 WINPR_UNUSED(instance->context);
66 auto client_id = from_settings(instance->context->settings, FreeRDP_GatewayAvdClientID);
67 std::string redirect_uri =
"ms-appx-web%3a%2f%2fMicrosoft.AAD.BrokerPlugin%2f" + client_id;
71 auto ep = from_aad_wellknown(instance->context, AAD_WELLKNOWN_authorization_endpoint);
72 auto url = ep +
"?client_id=" + client_id +
"&response_type=code&scope=" + scope +
73 "&redirect_uri=" + redirect_uri;
75 const std::string title =
"FreeRDP WebView - AAD access token";
77 auto rc = webview_impl_run(title, url, code);
78 if (!rc || code.empty())
81 auto token_request =
"grant_type=authorization_code&code=" + code +
"&client_id=" + client_id +
82 "&scope=" + scope +
"&redirect_uri=" + redirect_uri +
83 "&req_cnf=" + req_cnf;
84 return client_common_get_access_token(instance, token_request.c_str(), token);
87 static BOOL sdl_webview_get_avd_access_token(freerdp* instance,
char** token)
90 WINPR_ASSERT(instance);
91 WINPR_ASSERT(instance->context);
93 auto client_id = from_settings(instance->context->settings, FreeRDP_GatewayAvdClientID);
94 std::string redirect_uri =
"ms-appx-web%3a%2f%2fMicrosoft.AAD.BrokerPlugin%2f" + client_id;
95 std::string scope =
"https%3A%2F%2Fwww.wvd.microsoft.com%2F.default";
99 auto ep = from_aad_wellknown(instance->context, AAD_WELLKNOWN_authorization_endpoint);
100 auto url = ep +
"?client_id=" + client_id +
"&response_type=code&scope=" + scope +
101 "&redirect_uri=" + redirect_uri;
102 const std::string title =
"FreeRDP WebView - AVD access token";
104 auto rc = webview_impl_run(title, url, code);
105 if (!rc || code.empty())
108 auto token_request =
"grant_type=authorization_code&code=" + code +
"&client_id=" + client_id +
109 "&scope=" + scope +
"&redirect_uri=" + redirect_uri;
110 return client_common_get_access_token(instance, token_request.c_str(), token);
113 BOOL sdl_webview_get_access_token(freerdp* instance, AccessTokenType tokenType,
char** token,
116 WINPR_ASSERT(instance);
120 case ACCESS_TOKEN_TYPE_AAD:
125 "ACCESS_TOKEN_TYPE_AAD expected 2 additional arguments, but got %" PRIuz
132 "ACCESS_TOKEN_TYPE_AAD expected 2 additional arguments, but got %" PRIuz
137 const char* scope = va_arg(ap,
const char*);
138 const char* req_cnf = va_arg(ap,
const char*);
139 const BOOL rc = sdl_webview_get_rdsaad_access_token(instance, scope, req_cnf, token);
143 case ACCESS_TOKEN_TYPE_AVD:
146 "ACCESS_TOKEN_TYPE_AVD expected 0 additional arguments, but got %" PRIuz
149 return sdl_webview_get_avd_access_token(instance, token);
151 WLog_ERR(TAG,
"Unexpected value for AccessTokenType [%" PRIuz
"], aborting", tokenType);
FREERDP_API const char * freerdp_settings_get_string(const rdpSettings *settings, FreeRDP_Settings_Keys_String id)
Returns a immutable string settings value.
FREERDP_API const char * freerdp_settings_get_name_for_key(SSIZE_T key)
Returns the type name for a key.