Kurlyk
Loading...
Searching...
No Matches
kurlyk::http::auth::OAuthPkceClient Class Reference

Implements the OAuth2 Authorization Code flow with optional PKCE. More...

#include <OAuthPkceClient.hpp>

Public Types

using TokenParser
 Callback type for custom token parsing when JSON support is disabled.

Public Member Functions

 OAuthPkceClient (const OAuthConfig &config)
 Constructs a client with the given OAuth configuration.
void set_token_parser (TokenParser parser)
 Sets a custom token parser for non-JSON builds.
std::string build_authorization_url ()
 Builds the full authorization URL with query parameters.
bool exchange_code (const std::string &code, AuthResult &out_result)
 Exchanges an authorization code for an access token.
bool refresh_access_token (const std::string &refresh_token, AuthResult &out_result)
 Refreshes an access token using a refresh token.
bool validate_state (const std::string &returned_state) const
 Validates the state parameter returned by the authorization server.
const std::string & code_verifier () const
 Returns the code verifier used in the last PKCE exchange.
const std::string & state () const
 Returns the state parameter used in the last authorization request.

Protected Member Functions

bool parse_token_response (const std::string &raw_response, AuthResult &out_result)

Private Attributes

OAuthConfig m_config
std::string m_code_verifier
std::string m_code_challenge
std::string m_state
TokenParser m_token_parser

Detailed Description

Implements the OAuth2 Authorization Code flow with optional PKCE.

Uses the standalone free functions kurlyk::http_post and kurlyk::http_request so it does not depend on any particular HttpClient instance.

Definition at line 31 of file OAuthPkceClient.hpp.

Member Typedef Documentation

◆ TokenParser

Initial value:
std::function<bool(
const std::string& raw_response,
OAuthToken& out_token,
std::string& out_error)>
Holds the result of an OAuth2 token exchange.

Callback type for custom token parsing when JSON support is disabled.

Definition at line 34 of file OAuthPkceClient.hpp.

Constructor & Destructor Documentation

◆ OAuthPkceClient()

kurlyk::http::auth::OAuthPkceClient::OAuthPkceClient ( const OAuthConfig & config)
inlineexplicit

Constructs a client with the given OAuth configuration.

Parameters
configOAuth client configuration.

Definition at line 41 of file OAuthPkceClient.hpp.

Member Function Documentation

◆ build_authorization_url()

std::string kurlyk::http::auth::OAuthPkceClient::build_authorization_url ( )
inline

Builds the full authorization URL with query parameters.

Returns
The authorization URL ready to open in a browser.

Definition at line 52 of file OAuthPkceClient.hpp.

◆ code_verifier()

const std::string & kurlyk::http::auth::OAuthPkceClient::code_verifier ( ) const
inline

Returns the code verifier used in the last PKCE exchange.

Definition at line 227 of file OAuthPkceClient.hpp.

◆ exchange_code()

bool kurlyk::http::auth::OAuthPkceClient::exchange_code ( const std::string & code,
AuthResult & out_result )
inline

Exchanges an authorization code for an access token.

Parameters
codeThe authorization code received from the OAuth server.
out_resultReceives the authentication result.
Returns
true on success; inspect out_result on failure.

Definition at line 97 of file OAuthPkceClient.hpp.

◆ parse_token_response()

bool kurlyk::http::auth::OAuthPkceClient::parse_token_response ( const std::string & raw_response,
AuthResult & out_result )
inlineprotected

Definition at line 237 of file OAuthPkceClient.hpp.

◆ refresh_access_token()

bool kurlyk::http::auth::OAuthPkceClient::refresh_access_token ( const std::string & refresh_token,
AuthResult & out_result )
inline

Refreshes an access token using a refresh token.

Parameters
refresh_tokenThe refresh token.
out_resultReceives the authentication result.
Returns
true on success; inspect out_result on failure.

Definition at line 162 of file OAuthPkceClient.hpp.

◆ set_token_parser()

void kurlyk::http::auth::OAuthPkceClient::set_token_parser ( TokenParser parser)
inline

Sets a custom token parser for non-JSON builds.

Parameters
parserCallback invoked when JSON support is unavailable.

Definition at line 46 of file OAuthPkceClient.hpp.

◆ state()

const std::string & kurlyk::http::auth::OAuthPkceClient::state ( ) const
inline

Returns the state parameter used in the last authorization request.

Definition at line 232 of file OAuthPkceClient.hpp.

◆ validate_state()

bool kurlyk::http::auth::OAuthPkceClient::validate_state ( const std::string & returned_state) const
inline

Validates the state parameter returned by the authorization server.

Parameters
returned_stateThe state parameter from the redirect.
Returns
true if the state matches the internally stored value.

Definition at line 222 of file OAuthPkceClient.hpp.

Member Data Documentation

◆ m_code_challenge

std::string kurlyk::http::auth::OAuthPkceClient::m_code_challenge
private

Definition at line 299 of file OAuthPkceClient.hpp.

◆ m_code_verifier

std::string kurlyk::http::auth::OAuthPkceClient::m_code_verifier
private

Definition at line 298 of file OAuthPkceClient.hpp.

◆ m_config

OAuthConfig kurlyk::http::auth::OAuthPkceClient::m_config
private

Definition at line 297 of file OAuthPkceClient.hpp.

◆ m_state

std::string kurlyk::http::auth::OAuthPkceClient::m_state
private

Definition at line 300 of file OAuthPkceClient.hpp.

◆ m_token_parser

TokenParser kurlyk::http::auth::OAuthPkceClient::m_token_parser
private

Definition at line 301 of file OAuthPkceClient.hpp.


The documentation for this class was generated from the following file: