xentara-plugin v2.1
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.
 
constexpr auto allowedOrigins () const noexcept -> std::span< const CorsOriginPattern >
 Gets the list of allowed CORS origins.
 
constexpr auto allowCorsCredentials () const noexcept -> bool
 Checks whether CORS requests are allowed to include credentials.
 
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 setAllowedOrigins (std::vector< CorsOriginPattern > allowedOrigins) -> void
 Sets the list of allowed CORS origins.
 
auto setAllowCorsCredentials (bool allowCredentials) -> void
 Specifies whether CORS requests should be allowed to include credentials.
 
auto loadAuthentication (utils::json::decoder::Value &value, config::Context &context) -> void
 Loads the authentication configuration from a JSON value.
 
auto loadCors (utils::json::decoder::Value &value, config::Context &context) -> void
 Loads the CORS (Cross-Origin Resource Sharing) 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.
 

Deprecated Functions

auto load (utils::json::decoder::Value &value, config::Context &context) -> void
 deprecated Loads the authentication configuration from a JSON value.
 

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 authentication configuration allows OAuth 2.0 authentication using the authentication realm “Xentara” and the default scope configured in the global Xentara OAuth 2.0 configuration.

The default CORS configuration allows all origins.

Member Function Documentation

◆ allowCorsCredentials()

constexpr auto xentara::security::HttpConfig::allowCorsCredentials ( ) const -> bool
constexprnoexcept

Checks whether CORS requests are allowed to include credentials.

Returns
Returns the value for the CORS header “Access-Control-Allow-Credentials”. If this function returns true, then responses to CORS requests should include the header “Access-Control-Allow-Credentials” set to “true”. If this function returns false, then the header value should be “false”, or the header should be omitted altogether.

◆ allowedOrigins()

constexpr auto xentara::security::HttpConfig::allowedOrigins ( ) const -> std::span<const CorsOriginPattern>
constexprnoexcept

Gets the list of allowed CORS origins.

◆ 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

deprecated Loads the authentication configuration from a JSON value.

Deprecated:
Replaced by loadAuthentication()

◆ loadAuthentication()

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

Loads the authentication configuration from a JSON value.

Normally, the name of the configuration parameter containing the authentication configuration should be called “authentication”. If necessary, a different name can be used, however, like “HTTPAuthentication”.

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

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

◆ loadCors()

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

Loads the CORS (Cross-Origin Resource Sharing) configuration from a JSON value.

Normally, the name of the configuration parameter containing the authentication configuration should be called “CORS”. If necessary, a different name can be used, however, like “HTTPCORS”.

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

Parameters
valueThe value to load the CORS 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.

◆ setAllowCorsCredentials()

auto xentara::security::HttpConfig::setAllowCorsCredentials ( bool  allowCredentials) -> void

Specifies whether CORS requests should be allowed to include credentials.

Parameters
allowCredentialsWhether responses to CORS requests should include “Access-Control-Allow-Credentials: true”.

◆ setAllowedOrigins()

auto xentara::security::HttpConfig::setAllowedOrigins ( std::vector< CorsOriginPattern >  allowedOrigins) -> void

Sets the list of allowed CORS origins.

Parameters
allowedOriginsThe list of allowed origins. If you pass an empty list, no origins will be allowed.

◆ 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.