Kurlyk
Toggle main menu visibility
Loading...
Searching...
No Matches
AuthResult.hpp
Go to the documentation of this file.
1
#pragma once
2
#ifndef _KURLYK_HTTP_AUTH_DATA_AUTH_RESULT_HPP_INCLUDED
3
#define _KURLYK_HTTP_AUTH_DATA_AUTH_RESULT_HPP_INCLUDED
4
7
8
#include <string>
9
#include "
OAuthToken.hpp
"
10
11
#if KURLYK_JSON_SUPPORT
12
# include <nlohmann/json.hpp>
13
#endif
14
15
namespace
kurlyk
{
16
19
enum class
AuthError
{
20
None
,
21
InvalidConfig
,
22
HttpError
,
23
InvalidResponse
,
24
TokenExpired
,
25
UnsupportedFlow
,
26
StateMismatch
27
};
28
31
struct
AuthResult
{
32
bool
success
=
false
;
33
AuthError
error
=
AuthError::None
;
34
std::string
error_message
;
35
OAuthToken
token
;
36
std::string
raw_response
;
37
};
38
39
}
// namespace kurlyk
40
41
#if KURLYK_JSON_SUPPORT
42
43
namespace
kurlyk
{
44
45
inline
void
to_json(nlohmann::json& j,
const
AuthError
& e) {
46
switch
(e) {
47
case
AuthError::None
: j =
"None"
;
break
;
48
case
AuthError::InvalidConfig
: j =
"InvalidConfig"
;
break
;
49
case
AuthError::HttpError
: j =
"HttpError"
;
break
;
50
case
AuthError::InvalidResponse
: j =
"InvalidResponse"
;
break
;
51
case
AuthError::TokenExpired
: j =
"TokenExpired"
;
break
;
52
case
AuthError::UnsupportedFlow
: j =
"UnsupportedFlow"
;
break
;
53
case
AuthError::StateMismatch
: j =
"StateMismatch"
;
break
;
54
default
: j =
"Unknown"
;
break
;
55
}
56
}
57
58
inline
void
from_json
(
const
nlohmann::json& j,
AuthError
& e) {
59
const
std::string s = j.get<std::string>();
60
if
(s ==
"None"
) e =
AuthError::None
;
61
else
if
(s ==
"InvalidConfig"
) e =
AuthError::InvalidConfig
;
62
else
if
(s ==
"HttpError"
) e =
AuthError::HttpError
;
63
else
if
(s ==
"InvalidResponse"
) e =
AuthError::InvalidResponse
;
64
else
if
(s ==
"TokenExpired"
) e =
AuthError::TokenExpired
;
65
else
if
(s ==
"UnsupportedFlow"
) e =
AuthError::UnsupportedFlow
;
66
else
if
(s ==
"StateMismatch"
) e =
AuthError::StateMismatch
;
67
else
e =
AuthError::None
;
68
}
69
70
inline
void
to_json
(nlohmann::json& j,
const
AuthResult
& r) {
71
j = nlohmann::json{
72
{
"success"
, r.success},
73
{
"error"
, r.error},
74
{
"error_message"
, r.error_message},
75
{
"token"
, r.token},
76
{
"raw_response"
, r.raw_response}
77
};
78
}
79
80
inline
void
from_json
(
const
nlohmann::json& j,
AuthResult
& r) {
81
if
(j.contains(
"success"
)) r.success = j[
"success"
].get<
bool
>();
82
if
(j.contains(
"error"
)) r.error = j[
"error"
].get<
AuthError
>();
83
if
(j.contains(
"error_message"
)) r.error_message = j[
"error_message"
].get<std::string>();
84
if
(j.contains(
"token"
)) r.token = j[
"token"
].get<
OAuthToken
>();
85
if
(j.contains(
"raw_response"
)) r.
raw_response
= j[
"raw_response"
].get<std::string>();
86
}
87
88
}
// namespace kurlyk
89
90
#endif
// KURLYK_JSON_SUPPORT
91
92
#endif
// _KURLYK_HTTP_AUTH_DATA_AUTH_RESULT_HPP_INCLUDED
OAuthToken.hpp
Defines the OAuthToken structure for storing OAuth2 token data.
cryptox::to_json
void to_json(nlohmann::json &j, const ProxyConfig &config)
Serializes ProxyConfig to JSON.
Definition
ProxyConfig.hpp:106
cryptox::from_json
void from_json(const nlohmann::json &j, ProxyConfig &config)
Deserializes ProxyConfig from JSON.
Definition
ProxyConfig.hpp:116
kurlyk
Primary namespace for the Kurlyk library, encompassing initialization, request management,...
kurlyk::AuthError
AuthError
Classification of authentication errors.
Definition
AuthResult.hpp:19
kurlyk::AuthError::HttpError
@ HttpError
HTTP request failed (non-2xx status or transport error).
Definition
AuthResult.hpp:22
kurlyk::AuthError::InvalidResponse
@ InvalidResponse
Server response could not be parsed.
Definition
AuthResult.hpp:23
kurlyk::AuthError::InvalidConfig
@ InvalidConfig
Missing or invalid client configuration.
Definition
AuthResult.hpp:21
kurlyk::AuthError::None
@ None
No error; operation succeeded.
Definition
AuthResult.hpp:20
kurlyk::AuthError::UnsupportedFlow
@ UnsupportedFlow
The requested OAuth flow is not supported.
Definition
AuthResult.hpp:25
kurlyk::AuthError::StateMismatch
@ StateMismatch
Returned state parameter does not match expected value.
Definition
AuthResult.hpp:26
kurlyk::AuthError::TokenExpired
@ TokenExpired
The token has expired and refresh failed.
Definition
AuthResult.hpp:24
kurlyk::AuthResult
Encapsulates the outcome of an authentication operation.
Definition
AuthResult.hpp:31
kurlyk::AuthResult::error_message
std::string error_message
Human-readable error description (if any).
Definition
AuthResult.hpp:34
kurlyk::AuthResult::error
AuthError error
Error classification.
Definition
AuthResult.hpp:33
kurlyk::AuthResult::raw_response
std::string raw_response
Raw server response body for diagnostics.
Definition
AuthResult.hpp:36
kurlyk::AuthResult::success
bool success
Whether the operation succeeded.
Definition
AuthResult.hpp:32
kurlyk::AuthResult::token
OAuthToken token
Token data on success (may be partially filled on failure).
Definition
AuthResult.hpp:35
kurlyk::OAuthToken
Holds the result of an OAuth2 token exchange.
Definition
OAuthToken.hpp:19
kurlyk::OAuthToken::raw_response
std::string raw_response
Raw server response body for debugging.
Definition
OAuthToken.hpp:25
include
kurlyk
http
auth
data
AuthResult.hpp
Generated by
1.17.0