Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ jobs:

- name: Install vcpkg dependencies
run: |
${{ github.workspace }}\vcpkg\vcpkg install cpprestsdk:x64-windows openssl:x64-windows boost-system:x64-windows boost-date-time:x64-windows boost-regex:x64-windows
${{ github.workspace }}\vcpkg\vcpkg install cpp-httplib:x64-windows nlohmann-json:x64-windows openssl:x64-windows
shell: cmd
env:
VCPKG_BINARY_SOURCES: 'clear;files,${{ github.workspace }}/vcpkg-binary-cache,readwrite'
Expand Down
4 changes: 2 additions & 2 deletions auth0_flutter/EXAMPLES.md
Original file line number Diff line number Diff line change
Expand Up @@ -503,7 +503,7 @@ cd C:\vcpkg
setx VCPKG_ROOT "C:\vcpkg"
```

The plugin's `vcpkg.json` manifest automatically pulls the required packages (`cpprestsdk`, `openssl`, `boost-system`, `boost-date-time`, `boost-regex`) at build time — no manual `vcpkg install` is needed.
The plugin's `vcpkg.json` manifest automatically pulls the required packages (`cpp-httplib`, `nlohmann-json`, `openssl`) at build time — no manual `vcpkg install` is needed.

#### 2. Configure your app's CMakeLists.txt

Expand All @@ -525,7 +525,7 @@ project(your_app LANGUAGES CXX)
# ... rest of your CMakeLists.txt ...
```

> ⚠️ The `CMAKE_TOOLCHAIN_FILE` line **must** appear before `project()`. If it appears after, CMake will have already configured the compiler and vcpkg packages will not be found, resulting in build errors like `Could not find a package configuration file provided by "cpprestsdk"`.
> ⚠️ The `CMAKE_TOOLCHAIN_FILE` line **must** appear before `project()`. If it appears after, CMake will have already configured the compiler and vcpkg packages will not be found, resulting in build errors like `Could not find a package configuration file provided by "httplib"`.

#### 3. Register the custom URL scheme (protocol handler)

Expand Down
26 changes: 9 additions & 17 deletions auth0_flutter/windows/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,6 @@
# customers of the plugin.
cmake_minimum_required(VERSION 3.14)

# CMP0167 (FindBoost deprecation) was introduced in CMake 3.27.
# Guard it so the file stays compatible with older CMake versions.
if(POLICY CMP0167)
cmake_policy(SET CMP0167 NEW)
endif()

#if (DEFINED ENV{VCPKG_ROOT} AND EXISTS "$ENV{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake")
# set(CMAKE_TOOLCHAIN_FILE "$ENV{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake"
# CACHE STRING "Vcpkg toolchain file")
Expand Down Expand Up @@ -40,10 +34,10 @@ list(APPEND PLUGIN_SOURCES
)

# === vcpkg dependencies ===
# These are resolved via vcpkg.json automatically (cpprestsdk, boost)
find_package(cpprestsdk CONFIG REQUIRED)
# These are resolved via vcpkg.json automatically (cpp-httplib, nlohmann-json, openssl)
find_package(httplib CONFIG REQUIRED)
find_package(nlohmann_json CONFIG REQUIRED)
find_package(OpenSSL REQUIRED)
find_package(Boost REQUIRED COMPONENTS system date_time regex)

# Define the plugin library target only if flutter targets are available
if(TARGET flutter)
Expand Down Expand Up @@ -89,6 +83,7 @@ if(TARGET flutter)
target_compile_definitions(${PLUGIN_NAME}
PRIVATE
_SILENCE_STDEXT_ARR_ITERS_DEPRECATION_WARNING
CPPHTTPLIB_OPENSSL_SUPPORT
)
# Source include directories and library dependencies.
target_include_directories(${PLUGIN_NAME} INTERFACE
Expand All @@ -100,12 +95,10 @@ if(TARGET flutter)
target_link_libraries(${PLUGIN_NAME} PRIVATE
flutter
flutter_wrapper_plugin
cpprestsdk::cpprest
httplib::httplib
nlohmann_json::nlohmann_json
OpenSSL::SSL
OpenSSL::Crypto
Boost::system
Boost::date_time
Boost::regex
)

# List of absolute paths to libraries that should be bundled with the plugin.
Expand Down Expand Up @@ -187,17 +180,16 @@ if (AUTH0_FLUTTER_ENABLE_TESTS)

target_compile_definitions(${TEST_RUNNER} PRIVATE
_SILENCE_STDEXT_ARR_ITERS_DEPRECATION_WARNING
CPPHTTPLIB_OPENSSL_SUPPORT
)

target_link_libraries(${TEST_RUNNER} PRIVATE
gtest_main
gmock
cpprestsdk::cpprest
httplib::httplib
nlohmann_json::nlohmann_json
OpenSSL::SSL
OpenSSL::Crypto
Boost::system
Boost::date_time
Boost::regex
)

# Link flutter_wrapper_plugin if available (when building as part of Flutter app)
Expand Down
18 changes: 8 additions & 10 deletions auth0_flutter/windows/auth0_api_client.cpp
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
#include "auth0_api_client.h"

#include <cpprest/json.h>
#include <nlohmann/json.hpp>
#include <windows.h>

#include <sstream>

using namespace web;

namespace auth0_flutter
{

Expand Down Expand Up @@ -65,15 +63,15 @@ static std::string GetWindowsVersion()

std::string BuildAuth0ClientHeader(const std::string &name, const std::string &version)
{
json::value env;
env[U("Windows")] = json::value::string(utility::conversions::to_string_t(GetWindowsVersion()));
nlohmann::json env;
env["Windows"] = GetWindowsVersion();

json::value payload;
payload[U("name")] = json::value::string(utility::conversions::to_string_t(name));
payload[U("version")] = json::value::string(utility::conversions::to_string_t(version));
payload[U("env")] = env;
nlohmann::json payload;
payload["name"] = name;
payload["version"] = version;
payload["env"] = env;

return Base64UrlEncode(utility::conversions::to_utf8string(payload.serialize()));
return Base64UrlEncode(payload.dump());
}

// ---------------------------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion auth0_flutter/windows/auth0_flutter_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ namespace auth0_flutter

// Pass a direct-call task runner. All operations posted through it
// (ShellExecuteW, window focus, MethodResult callbacks) are safe to
// invoke from a pplx background thread, so no UI-thread dispatch is
// invoke from a PPL background thread, so no UI-thread dispatch is
// required. This avoids depending on flutter::TaskRunner / GetTaskRunner()
// which was only introduced in Flutter 3.7 and may not exist on all
// build environments.
Expand Down
16 changes: 7 additions & 9 deletions auth0_flutter/windows/authentication_api_client.cpp
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
#include "authentication_api_client.h"

#include <cpprest/json.h>
#include <nlohmann/json.hpp>

#include "token_decoder.h"
#include "authentication_error.h"

using namespace web;

namespace auth0_flutter
{

Expand All @@ -15,12 +13,12 @@ Credentials AuthenticationApiClient::ExchangeCodeForTokens(
const std::string &code,
const std::string &codeVerifier)
{
json::value body;
body[U("grant_type")] = json::value::string(U("authorization_code"));
body[U("client_id")] = json::value::string(utility::conversions::to_string_t(clientId()));
body[U("code")] = json::value::string(utility::conversions::to_string_t(code));
body[U("redirect_uri")] = json::value::string(utility::conversions::to_string_t(redirectUri));
body[U("code_verifier")] = json::value::string(utility::conversions::to_string_t(codeVerifier));
nlohmann::json body;
body["grant_type"] = "authorization_code";
body["client_id"] = clientId();
body["code"] = code;
body["redirect_uri"] = redirectUri;
body["code_verifier"] = codeVerifier;

try
{
Expand Down
35 changes: 17 additions & 18 deletions auth0_flutter/windows/authentication_error.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#include <string>
#include <stdexcept>
#include <map>
#include <cpprest/json.h>
#include <nlohmann/json.hpp>

namespace auth0_flutter
{
Expand Down Expand Up @@ -46,34 +46,34 @@ namespace auth0_flutter
* - Legacy format: { "code": "...", "description": "..." }
*/
AuthenticationError(
const web::json::value &errorJson,
const nlohmann::json &errorJson,
int statusCode)
: std::runtime_error("An error occurred when trying to authenticate with the server."),
statusCode_(statusCode)
{
// Try modern format first: "error" and "error_description"
if (errorJson.has_field(U("error")))
if (errorJson.contains("error"))
{
code_ = GetJsonString(errorJson, U("error"));
code_ = GetJsonString(errorJson, "error");
}
else if (errorJson.has_field(U("code")))
else if (errorJson.contains("code"))
{
// Fallback to legacy format
code_ = GetJsonString(errorJson, U("code"));
code_ = GetJsonString(errorJson, "code");
}
else
{
code_ = "UNKNOWN_ERROR";
}

// Try "error_description" first, then "description"
if (errorJson.has_field(U("error_description")))
if (errorJson.contains("error_description"))
{
description_ = GetJsonString(errorJson, U("error_description"));
description_ = GetJsonString(errorJson, "error_description");
}
else if (errorJson.has_field(U("description")))
else if (errorJson.contains("description"))
{
description_ = GetJsonString(errorJson, U("description"));
description_ = GetJsonString(errorJson, "description");
}
else
{
Expand Down Expand Up @@ -110,10 +110,9 @@ namespace auth0_flutter
*/
std::string GetValue(const std::string &key) const
{
utility::string_t wkey = utility::conversions::to_string_t(key);
if (errorJson_.has_field(wkey))
if (errorJson_.contains(key))
{
return GetJsonString(errorJson_, wkey);
return GetJsonString(errorJson_, key);
}
return std::string();
}
Expand Down Expand Up @@ -255,15 +254,15 @@ namespace auth0_flutter
std::string code_;
std::string description_;
int statusCode_;
web::json::value errorJson_;
nlohmann::json errorJson_;

static std::string GetJsonString(
const web::json::value &json,
const utility::string_t &key)
const nlohmann::json &json,
const std::string &key)
{
if (json.has_field(key) && json.at(key).is_string())
if (json.contains(key) && json.at(key).is_string())
{
return utility::conversions::to_utf8string(json.at(key).as_string());
return json.at(key).get<std::string>();
}
return std::string();
}
Expand Down
Loading
Loading