Kurlyk
Loading...
Searching...
No Matches
OAuthConfig.hpp
Go to the documentation of this file.
1#pragma once
2#ifndef _KURLYK_HTTP_AUTH_DATA_OAUTH_CONFIG_HPP_INCLUDED
3#define _KURLYK_HTTP_AUTH_DATA_OAUTH_CONFIG_HPP_INCLUDED
4
7
8#include <string>
9
10#if KURLYK_JSON_SUPPORT
11# include <nlohmann/json.hpp>
12#endif
13
14namespace kurlyk {
15
18 struct OAuthConfig {
19 std::string client_id;
20 std::string client_secret;
22 std::string token_endpoint;
23 std::string redirect_uri;
24 std::string scope;
25 bool use_pkce = true;
26 std::string audience;
27 std::string prompt;
28 std::string access_type;
29 };
30
31} // namespace kurlyk
32
33#if KURLYK_JSON_SUPPORT
34
35namespace kurlyk {
36
37 inline void to_json(nlohmann::json& j, const OAuthConfig& c) {
38 j = nlohmann::json{
39 {"client_id", c.client_id},
40 {"client_secret", c.client_secret},
41 {"authorization_endpoint", c.authorization_endpoint},
42 {"token_endpoint", c.token_endpoint},
43 {"redirect_uri", c.redirect_uri},
44 {"scope", c.scope},
45 {"use_pkce", c.use_pkce},
46 {"audience", c.audience},
47 {"prompt", c.prompt},
48 {"access_type", c.access_type}
49 };
50 }
51
52 inline void from_json(const nlohmann::json& j, OAuthConfig& c) {
53 if (j.contains("client_id")) c.client_id = j["client_id"].get<std::string>();
54 if (j.contains("client_secret")) c.client_secret = j["client_secret"].get<std::string>();
55 if (j.contains("authorization_endpoint")) c.authorization_endpoint = j["authorization_endpoint"].get<std::string>();
56 if (j.contains("token_endpoint")) c.token_endpoint = j["token_endpoint"].get<std::string>();
57 if (j.contains("redirect_uri")) c.redirect_uri = j["redirect_uri"].get<std::string>();
58 if (j.contains("scope")) c.scope = j["scope"].get<std::string>();
59 if (j.contains("use_pkce")) c.use_pkce = j["use_pkce"].get<bool>();
60 if (j.contains("audience")) c.audience = j["audience"].get<std::string>();
61 if (j.contains("prompt")) c.prompt = j["prompt"].get<std::string>();
62 if (j.contains("access_type")) c.access_type = j["access_type"].get<std::string>();
63 }
64
65} // namespace kurlyk
66
67#endif // KURLYK_JSON_SUPPORT
68
69#endif // _KURLYK_HTTP_AUTH_DATA_OAUTH_CONFIG_HPP_INCLUDED
void from_json(const nlohmann::json &j, ProxyConfig &config)
Deserializes ProxyConfig from JSON.
Primary namespace for the Kurlyk library, encompassing initialization, request management,...
Stores client configuration for an OAuth2 Authorization Code + PKCE flow.
std::string prompt
Optional prompt parameter (e.g. "consent").
std::string client_secret
Client secret (optional, usually empty for public/PKCE clients).
std::string redirect_uri
Registered redirect URI.
std::string audience
Optional audience parameter.
std::string client_id
OAuth2 client identifier.
std::string access_type
Optional access_type parameter (e.g. "offline").
bool use_pkce
Whether to use PKCE (RFC 7636). Default true.
std::string authorization_endpoint
Authorization server URL.
std::string token_endpoint
Token exchange URL.
std::string scope
Space-separated requested scopes.