diff options
| author | Stefan Boberg <[email protected]> | 2026-02-27 16:08:58 +0100 |
|---|---|---|
| committer | Stefan Boberg <[email protected]> | 2026-02-27 16:08:58 +0100 |
| commit | ff0bf54463374d90a99ecedbf6dd940dfbfe6e83 (patch) | |
| tree | cfece7996397f424e3bcc4f2f39ed8e7e9835291 /src/zenhttp/auth | |
| parent | add SuppressDefaultConsoleOutput (diff) | |
| download | zen-sb/oidc-token.tar.xz zen-sb/oidc-token.zip | |
added support for encrypted remote config, fixed console outputsb/oidc-token
Diffstat (limited to 'src/zenhttp/auth')
| -rw-r--r-- | src/zenhttp/auth/oidc.cpp | 31 |
1 files changed, 28 insertions, 3 deletions
diff --git a/src/zenhttp/auth/oidc.cpp b/src/zenhttp/auth/oidc.cpp index 4b306236c..eea81fbdb 100644 --- a/src/zenhttp/auth/oidc.cpp +++ b/src/zenhttp/auth/oidc.cpp @@ -28,6 +28,27 @@ namespace details { return Result; } + std::string UrlEncodeFormValue(std::string_view Input) + { + std::string Result; + Result.reserve(Input.size()); + for (unsigned char Ch : Input) + { + if ((Ch >= 'A' && Ch <= 'Z') || (Ch >= 'a' && Ch <= 'z') || (Ch >= '0' && Ch <= '9') || Ch == '-' || Ch == '_' || Ch == '.' || + Ch == '~') + { + Result += static_cast<char>(Ch); + } + else + { + char Hex[4]; + snprintf(Hex, sizeof(Hex), "%%%02X", Ch); + Result.append(Hex, 3); + } + } + return Result; + } + } // namespace details using namespace std::literals; @@ -81,7 +102,9 @@ OidcClient::Initialize() OidcClient::RefreshTokenResult OidcClient::RefreshToken(std::string_view RefreshToken) { - const std::string Body = fmt::format("grant_type=refresh_token&refresh_token={}&client_id={}", RefreshToken, m_ClientId); + const std::string Body = fmt::format("grant_type=refresh_token&refresh_token={}&client_id={}", + details::UrlEncodeFormValue(RefreshToken), + details::UrlEncodeFormValue(m_ClientId)); HttpClient Http{m_Config.TokenEndpoint}; @@ -119,8 +142,10 @@ OidcClient::RefreshToken(std::string_view RefreshToken) OidcClient::RefreshTokenResult OidcClient::ExchangeAuthorizationCode(std::string_view Code, std::string_view RedirectUri) { - const std::string Body = - fmt::format("grant_type=authorization_code&code={}&redirect_uri={}&client_id={}", Code, RedirectUri, m_ClientId); + const std::string Body = fmt::format("grant_type=authorization_code&code={}&redirect_uri={}&client_id={}", + details::UrlEncodeFormValue(Code), + details::UrlEncodeFormValue(RedirectUri), + details::UrlEncodeFormValue(m_ClientId)); HttpClient Http{m_Config.TokenEndpoint}; |