dxFeed Graal CXX API v9.0.0
Loading...
Searching...
No Matches
AuthToken Struct Reference

The AuthToken class represents an authorization token and encapsulates information about the authorization scheme and its associated value. More...

#include <AuthToken.hpp>

Public Member Functions

std::string getHttpAuthorization () const
 Returns the HTTP authorization header value.
std::string getUser () const
 Returns the username or dxfcpp::String::NUL (std::string{"<null>"}) if it is not known or applicable.
std::string getPassword () const
 Returns the password or dxfcpp::String::NUL (std::string{"<null>"}) if it is not known or applicable.
std::string getScheme () const
 Returns the authentication scheme.
std::string getValue () const
 Returns the access token for RFC6750 or the Base64-encoded "username:password" for RFC2617.

Static Public Member Functions

static AuthToken valueOf (StringParam string)
 Constructs an AuthToken from the specified string.
static AuthToken createBasicToken (StringParam userPassword)
 Constructs an AuthToken with the specified username and password per RFC2617.
static AuthToken createBasicToken (StringParam user, StringParam password)
 Constructs an AuthToken with the specified username and password per RFC2617.
static AuthToken createBasicTokenOrNull (StringParam user, StringParam password)
 Constructs an AuthToken with the specified username and password per RFC2617.
static AuthToken createBearerToken (StringParam token)
 Constructs an AuthToken with the specified bearer token per RFC6750.
static AuthToken createBearerTokenOrNull (StringParam token)
 Constructs an AuthToken with the specified bearer token per RFC6750.
static AuthToken createCustomToken (StringParam scheme, StringParam value)
 Constructs an AuthToken with a custom scheme and value.

Static Public Attributes

static constexpr char BASIC_SCHEME [] = "Basic"
 String representation for Basic (Base64(login:password)) authorization.
static constexpr char BEARER_SCHEME [] = "Bearer"
 String representation for the Bearer (token) authorization.
static const AuthToken NULL_TOKEN {}
 A stub that is needed to simulate null AuthToken without using std::optional.

Detailed Description

The AuthToken class represents an authorization token and encapsulates information about the authorization scheme and its associated value.

An AuthToken consists of the following components:

  • Scheme - The authorization scheme (e.g., "Basic" or "Bearer").
  • Value - The encoded value, which is scheme-dependent (e.g., an access token per RFC6750 or Base64-encoded "user:password" per RFC2617).
  • String representation - A string that combines the scheme and value in the format: [scheme + " " + value].

Member Function Documentation

◆ createBasicToken() [1/2]

AuthToken AuthToken::createBasicToken ( StringParam user,
StringParam password )
static

Constructs an AuthToken with the specified username and password per RFC2617.

Username and password can be empty.

Parameters
userThe username.
passwordThe password.
Returns
The constructed AuthToken.
Exceptions
InvalidArgumentExceptionif the username or the password is not valid UTF-8 (the message names the offset, not the bytes).

◆ createBasicToken() [2/2]

AuthToken AuthToken::createBasicToken ( StringParam userPassword)
static

Constructs an AuthToken with the specified username and password per RFC2617.

Username and password can be empty.

Parameters
userPasswordthe string (or c-string or string view) containing the username and password in the format "username:password"
Returns
The constructed AuthToken.
Exceptions
InvalidArgumentExceptionif the userPassword is not valid UTF-8 (the message names the offset, not the bytes).
JavaException("InvalidFormatException")if the userPassword is malformed

◆ createBasicTokenOrNull()

AuthToken AuthToken::createBasicTokenOrNull ( StringParam user,
StringParam password )
static

Constructs an AuthToken with the specified username and password per RFC2617.

If both the username and password are empty, returns AuthToken::NULL_TOKEN.

Parameters
userthe username
passwordthe password
Returns
the constructed AuthToken or AuthToken::NULL_TOKEN

◆ createBearerToken()

AuthToken AuthToken::createBearerToken ( StringParam token)
static

Constructs an AuthToken with the specified bearer token per RFC6750.

Parameters
tokenthe access token
Returns
the constructed AuthToken
Exceptions
InvalidArgumentExceptionif the token is not valid UTF-8 (the message names the offset, not the bytes).
JavaException("InvalidFormatException")if the token is empty

◆ createBearerTokenOrNull()

AuthToken AuthToken::createBearerTokenOrNull ( StringParam token)
static

Constructs an AuthToken with the specified bearer token per RFC6750.

Parameters
tokenthe access token
Returns
the constructed AuthToken or AuthToken::NULL_TOKEN.

◆ createCustomToken()

AuthToken AuthToken::createCustomToken ( StringParam scheme,
StringParam value )
static

Constructs an AuthToken with a custom scheme and value.

Parameters
schemethe custom scheme
valuethe custom value
Returns
the constructed AuthToken
Exceptions
InvalidArgumentExceptionif the scheme or the value is not valid UTF-8 (for the value the message names the offset, not the bytes).
JavaException("InvalidFormatException")if the scheme or value is empty

◆ getHttpAuthorization()

std::string AuthToken::getHttpAuthorization ( ) const

Returns the HTTP authorization header value.

Returns
the HTTP authorization header value

References String::NUL.

◆ getPassword()

std::string AuthToken::getPassword ( ) const

Returns the password or dxfcpp::String::NUL (std::string{"<null>"}) if it is not known or applicable.

Returns
the password, or dxfcpp::String::NUL (std::string{"<null>"}) if not known or applicable

References String::NUL.

◆ getScheme()

std::string AuthToken::getScheme ( ) const

Returns the authentication scheme.

Returns
the authentication scheme

References String::NUL.

◆ getUser()

std::string AuthToken::getUser ( ) const

Returns the username or dxfcpp::String::NUL (std::string{"<null>"}) if it is not known or applicable.

Returns
the username, or dxfcpp::String::NUL (std::string{"<null>"}) if not known or applicable

References String::NUL.

◆ getValue()

std::string AuthToken::getValue ( ) const

Returns the access token for RFC6750 or the Base64-encoded "username:password" for RFC2617.

Returns
the access token or Base64-encoded "username:password"

References String::NUL.

◆ valueOf()

AuthToken AuthToken::valueOf ( StringParam string)
static

Constructs an AuthToken from the specified string.

Parameters
stringThe string (or c-string or string view) with a space-separated scheme and value.
Returns
The constructed AuthToken.
Exceptions
JavaException("InvalidFormatException")if the string is malformed, or if the scheme is "Basic" but the format does not comply with RFC2617
See also
toString()