[client,sdl] move webview to static lib
* move to static lib aad-view * add support for https://github.com/webview/webview (e.g. use native webview if available)
This commit is contained in:
parent
80c7818f99
commit
8b0f4ca106
@ -79,6 +79,7 @@ set(SRCS
|
||||
sdl_channels.hpp
|
||||
sdl_channels.cpp)
|
||||
|
||||
add_subdirectory(aad)
|
||||
set(LIBS
|
||||
${SDL2_LIBRARIES}
|
||||
winpr
|
||||
@ -86,31 +87,14 @@ set(LIBS
|
||||
freerdp-client
|
||||
Threads::Threads
|
||||
dialogs
|
||||
aad-view
|
||||
)
|
||||
|
||||
option(WITH_WEBVIEW "Build with QtWebEngine support for AAD login popup browser" OFF)
|
||||
if (WITH_WEBVIEW)
|
||||
find_package(Qt5 COMPONENTS WebEngineWidgets REQUIRED)
|
||||
|
||||
list(APPEND SRCS
|
||||
sdl_webview.cpp
|
||||
sdl_webview.hpp
|
||||
)
|
||||
list(APPEND LIBS Qt5::WebEngineWidgets)
|
||||
endif()
|
||||
|
||||
add_executable(${PROJECT_NAME}
|
||||
${WIN32_GUI_FLAG}
|
||||
${SRCS}
|
||||
)
|
||||
|
||||
if (WITH_WEBVIEW)
|
||||
target_compile_definitions(
|
||||
${PROJECT_NAME} PRIVATE
|
||||
-DWITH_WEBVIEW
|
||||
)
|
||||
endif()
|
||||
|
||||
set_target_properties(${PROJECT_NAME}
|
||||
PROPERTIES
|
||||
OUTPUT_NAME "sdl-freerdp"
|
||||
|
71
client/SDL/aad/CMakeLists.txt
Normal file
71
client/SDL/aad/CMakeLists.txt
Normal file
@ -0,0 +1,71 @@
|
||||
option(WITH_WEBVIEW "Build with WebView support for AAD login popup browser" OFF)
|
||||
if (WITH_WEBVIEW)
|
||||
option(WITH_WEBVIEW_QT "Build with QtWebEngine support for AAD login broweser popup" OFF)
|
||||
|
||||
set(DEFINITIONS
|
||||
-DWITH_WEBVIEW
|
||||
)
|
||||
set(SRCS
|
||||
sdl_webview.h
|
||||
webview_impl.h
|
||||
sdl_webview.cpp
|
||||
)
|
||||
set(LIBS
|
||||
winpr
|
||||
)
|
||||
|
||||
if (WITH_WEBVIEW_QT)
|
||||
find_package(Qt5 COMPONENTS WebEngineWidgets REQUIRED)
|
||||
|
||||
list(APPEND SRCS
|
||||
qt/webview_impl.cpp
|
||||
)
|
||||
|
||||
list(APPEND LIBS
|
||||
Qt5::WebEngineWidgets
|
||||
)
|
||||
else()
|
||||
list(APPEND SRCS
|
||||
wrapper/webview.h
|
||||
wrapper/webview_impl.cpp
|
||||
)
|
||||
|
||||
if (WIN32)
|
||||
find_package(unofficial-webview2 CONFIG REQUIRED)
|
||||
list(APPEND LIBS
|
||||
unofficial::webview2::webview2
|
||||
)
|
||||
elseif(APPLE)
|
||||
find_library(WEBKIT Webkit REQUIRED)
|
||||
list(APPEND LIBS
|
||||
${WEBKIT}
|
||||
)
|
||||
else()
|
||||
include(FindPkgConfig)
|
||||
find_package(PkgConfig REQUIRED)
|
||||
pkg_check_modules(WEBVIEW_GTK webkit2gtk-4.0 REQUIRED)
|
||||
include_directories(${WEBVIEW_GTK_INCLUDE_DIRS})
|
||||
list(APPEND LIBS
|
||||
${WEBVIEW_GTK_LIBRARIES}
|
||||
)
|
||||
endif()
|
||||
endif()
|
||||
else()
|
||||
set(SRCS
|
||||
dummy.cpp
|
||||
)
|
||||
endif()
|
||||
|
||||
add_library(aad-view STATIC
|
||||
${SRCS}
|
||||
)
|
||||
target_link_libraries(aad-view
|
||||
PRIVATE
|
||||
${LIBS}
|
||||
)
|
||||
target_compile_definitions(
|
||||
aad-view
|
||||
PUBLIC
|
||||
${DEFINITIONS}
|
||||
)
|
||||
|
0
client/SDL/aad/dummy.cpp
Normal file
0
client/SDL/aad/dummy.cpp
Normal file
62
client/SDL/aad/sdl_webview.cpp
Normal file
62
client/SDL/aad/sdl_webview.cpp
Normal file
@ -0,0 +1,62 @@
|
||||
/**
|
||||
* FreeRDP: A Remote Desktop Protocol Implementation
|
||||
* Popup browser for AAD authentication
|
||||
*
|
||||
* Copyright 2023 Isaac Klein <fifthdegree@protonmail.com>
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include <string>
|
||||
#include <sstream>
|
||||
#include <stdlib.h>
|
||||
#include <winpr/string.h>
|
||||
|
||||
#include "sdl_webview.h"
|
||||
#include "webview_impl.h"
|
||||
|
||||
BOOL sdl_webview_get_aad_auth_code(freerdp* instance, const char* hostname, char** code,
|
||||
const char** client_id, const char** redirect_uri)
|
||||
{
|
||||
int argc = 1;
|
||||
std::string name = "FreeRDP WebView";
|
||||
|
||||
WINPR_ASSERT(instance);
|
||||
WINPR_ASSERT(hostname);
|
||||
WINPR_ASSERT(code);
|
||||
WINPR_ASSERT(client_id);
|
||||
WINPR_ASSERT(redirect_uri);
|
||||
|
||||
WINPR_UNUSED(instance);
|
||||
|
||||
*code = nullptr;
|
||||
*client_id = "5177bc73-fd99-4c77-a90c-76844c9b6999";
|
||||
*redirect_uri =
|
||||
"ms-appx-web%3a%2f%2fMicrosoft.AAD.BrokerPlugin%2f5177bc73-fd99-4c77-a90c-76844c9b6999";
|
||||
|
||||
std::stringstream url;
|
||||
url << "https://login.microsoftonline.com/common/oauth2/v2.0/authorize?client_id="
|
||||
<< std::string(*client_id)
|
||||
<< "&response_type=code&scope=ms-device-service%3A%2F%2Ftermsrv.wvd.microsoft.com%"
|
||||
"2Fname%2F"
|
||||
<< std::string(hostname)
|
||||
<< "%2Fuser_impersonation&redirect_uri=" << std::string(*redirect_uri);
|
||||
|
||||
auto urlstr = url.str();
|
||||
const std::string title = "FreeRDP WebView";
|
||||
std::string cxxcode;
|
||||
if (!webview_impl_run(title, urlstr, cxxcode))
|
||||
return FALSE;
|
||||
*code = _strdup(cxxcode.c_str());
|
||||
return TRUE;
|
||||
}
|
24
client/SDL/aad/webview_impl.h
Normal file
24
client/SDL/aad/webview_impl.h
Normal file
@ -0,0 +1,24 @@
|
||||
/**
|
||||
* FreeRDP: A Remote Desktop Protocol Implementation
|
||||
* Popup browser for AAD authentication
|
||||
*
|
||||
* Copyright 2023 Isaac Klein <fifthdegree@protonmail.com>
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
|
||||
bool webview_impl_run(const std::string& title, const std::string& url, std::string& code);
|
1
client/SDL/aad/wrapper/README
Normal file
1
client/SDL/aad/wrapper/README
Normal file
@ -0,0 +1 @@
|
||||
upstream at https://github.com/webview/webview/
|
2758
client/SDL/aad/wrapper/webview.h
Normal file
2758
client/SDL/aad/wrapper/webview.h
Normal file
File diff suppressed because it is too large
Load Diff
78
client/SDL/aad/wrapper/webview_impl.cpp
Normal file
78
client/SDL/aad/wrapper/webview_impl.cpp
Normal file
@ -0,0 +1,78 @@
|
||||
/**
|
||||
* FreeRDP: A Remote Desktop Protocol Implementation
|
||||
* Popup browser for AAD authentication
|
||||
*
|
||||
* Copyright 2023 Isaac Klein <fifthdegree@protonmail.com>
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "webview.h"
|
||||
|
||||
#include <assert.h>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <map>
|
||||
#include <regex>
|
||||
#include <sstream>
|
||||
#include "../webview_impl.h"
|
||||
|
||||
std::vector<std::string> split(const std::string& input, const std::string& regex)
|
||||
{
|
||||
// passing -1 as the submatch index parameter performs splitting
|
||||
std::regex re(regex);
|
||||
std::sregex_token_iterator first{ input.begin(), input.end(), re, -1 }, last;
|
||||
return { first, last };
|
||||
}
|
||||
|
||||
std::map<std::string, std::string> urlsplit(const std::string& url)
|
||||
{
|
||||
auto pos = url.find("?");
|
||||
if (pos == std::string::npos)
|
||||
return {};
|
||||
auto surl = url.substr(pos);
|
||||
auto args = split(surl, "&");
|
||||
|
||||
std::map<std::string, std::string> argmap;
|
||||
for (const auto& arg : args)
|
||||
{
|
||||
auto kv = split(arg, "=");
|
||||
if (kv.size() == 2)
|
||||
argmap.insert({ kv[0], kv[1] });
|
||||
}
|
||||
return argmap;
|
||||
}
|
||||
|
||||
static void fkt(const std::string& url, void* arg)
|
||||
{
|
||||
auto args = urlsplit(url);
|
||||
auto val = args.find("code");
|
||||
if (val == args.end())
|
||||
return;
|
||||
|
||||
assert(arg);
|
||||
auto rcode = static_cast<std::string*>(arg);
|
||||
*rcode = val->second;
|
||||
}
|
||||
|
||||
bool webview_impl_run(const std::string& title, const std::string& url, std::string& code)
|
||||
{
|
||||
webview::webview w(false, nullptr);
|
||||
w.set_title(title);
|
||||
w.set_size(640, 480, WEBVIEW_HINT_NONE);
|
||||
|
||||
w.add_navigate_listener(fkt, &code);
|
||||
w.navigate(url);
|
||||
w.run();
|
||||
return !code.empty();
|
||||
}
|
@ -57,7 +57,7 @@
|
||||
#include "dialogs/sdl_dialogs.hpp"
|
||||
|
||||
#ifdef WITH_WEBVIEW
|
||||
#include "sdl_webview.hpp"
|
||||
#include "aad/sdl_webview.h"
|
||||
#endif
|
||||
|
||||
#define SDL_TAG CLIENT_TAG("SDL")
|
||||
|
Loading…
x
Reference in New Issue
Block a user