xentara-plugin v2.0.4
The Xentara Plugin Framework
Loading...
Searching...
No Matches
xentara::security::HttpConfig Class Reference

Server-side authentication configuration for an HTTP based service. More...

#include <xentara/security/HttpConfig.hpp>

Public Member Functions

 HttpConfig ()
 Constructor for a default configuration.
 
constexpr auto realm () const noexcept -> std::string_view
 Gets the realm.
 
constexpr auto schemes () const noexcept -> std::span< const std::string >
 Gets the list of allowed schemes.
 
constexpr auto scope () const noexcept -> const Oauth2Scope &
 Gets the OAuth 2.0 scope.
 
auto setRealm (std::string realm) -> void
 Sets the realm.
 
auto setSchemes (std::vector< std::string > schemes) -> void
 Sets the list of supported HTTP authentication schemes.
 
auto setScheme (std::string scheme) -> void
 Sets the list of supported HTTP authentication schemes to a single scheme.
 
auto setScope (Oauth2Scope scope) -> void
 Sets the required OAuth 2.0 scope.
 
auto load (utils::json::decoder::Value &value, config::Context &context) -> void
 Loads the configuration from a JSON value.
 

Static Public Member Functions

static auto checkRealmString (std::string_view string) -> utils::eh::expected< void, std::string_view >
 Checks whether a string is a legal HTTP realm string.
 

Detailed Description

Server-side authentication configuration for an HTTP based service.

Constructor & Destructor Documentation

◆ HttpConfig()

xentara::security::HttpConfig::HttpConfig ( )

Constructor for a default configuration.

The default configuration allows OAuth 2.0 authentication using the authentication realm “Xentara” and the default scope configured in the global Xentara OAuth 2.0 configuration.

Member Function Documentation

◆ checkRealmString()

static auto xentara::security::HttpConfig::checkRealmString ( std::string_view  string) -> utils::eh::expected< void, std::string_view >
static

Checks whether a string is a legal HTTP realm string.

Parameters
stringThe string to check
Returns
A valid expected value, or an (English) error string describing the exact problem, suitable for display to the user.

◆ load()

auto xentara::security::HttpConfig::load ( utils::json::decoder::Value value,
config::Context context 
) -> void

Loads the configuration from a JSON value.

Normally, the name of the configuration parameter containing the configuration should be called “authentication”, because this object contains information about the HTTP authentication configuration. If necessary, a different name can be used, however, like “HTTPAuthentication”.

The configuration parameter for the configuration can generally be optional. If the parameter is not specified in the configuration, the default configuration created by the default constructor should be used.

Parameters
valueThe value to load the parameters from.
contextThe configuration context.
Exceptions
std::runtime_errorThe configuration is not valid, or another error occurred.

◆ realm()

constexpr auto xentara::security::HttpConfig::realm ( ) const -> std::string_view
constexprnoexcept

Gets the realm.

◆ schemes()

constexpr auto xentara::security::HttpConfig::schemes ( ) const -> std::span<const std::string>
constexprnoexcept

Gets the list of allowed schemes.

◆ scope()

constexpr auto xentara::security::HttpConfig::scope ( ) const -> const Oauth2Scope &
constexprnoexcept

Gets the OAuth 2.0 scope.

Note
The OAuth 2.0 scope is only used by the “Bearer” authentication scheme. The “Basic” authentication scheme does not have a concept of scope, and ignores this setting.
Returns
Returns the OAuth 2.0 scope contained in the configuration as a list of scope strings, or a default constructed Oauth2Scope object, if the default scope configured in the global Xentara OAuth 2.0 configuration will be used. You can use Oauth2Scope::operator!() to check whether the returned scope contains a cústom scope or not.

◆ setRealm()

auto xentara::security::HttpConfig::setRealm ( std::string  realm) -> void

Sets the realm.

Parameters
realmThe realm. Must be a valid realm string. You can use checkRealmString() to check the realm string for validity.
Exceptions
std::invaid_parameterrealm is not a valid HTTP realm string.

◆ setScheme()

auto xentara::security::HttpConfig::setScheme ( std::string  scheme) -> void

Sets the list of supported HTTP authentication schemes to a single scheme.

Parameters
schemeThe scheme. Must be a supported HTTP authentication scheme. The supported schemes are “Bearer” for OAuth 2.0 authentication using bearer tokens, and “Basic” for HTTP user/password authentication.
Exceptions
std::invaid_parameterscheme is not a supported HTTP authentication scheme.

◆ setSchemes()

auto xentara::security::HttpConfig::setSchemes ( std::vector< std::string schemes) -> void

Sets the list of supported HTTP authentication schemes.

Parameters
schemesThe list of supported schemes. Each scheme must be a supported HTTP authentication scheme. The supported schemes are “Bearer” for OAuth 2.0 authentication using bearer tokens, and “Basic” for HTTP user/password authentication.
Exceptions
std::invaid_parameterschemes contains a string that is not a supported HTTP authentication scheme.

◆ setScope()

auto xentara::security::HttpConfig::setScope ( Oauth2Scope  scope) -> void

Sets the required OAuth 2.0 scope.

Note
The OAuth 2.0 scope is only used by the “Bearer” authentication scheme. The “Basic” authentication scheme does not have a concept of scope, and ignores this setting.
Parameters
scopeThe scope to use, or a default constructed Oauth2Scope object to use the default scope configured in the global Xentara OAuth 2.0 configuration.