10Duke Scale C++ Client
Loading...
Searching...
No Matches
tenduke::oauth::OAuthStateServiceImpl Class Reference

#include <OAuthStateServiceImpl.h>

Detailed Description

Default implementation of tenduke::oauth::OAuthStateService.

Inheritance diagram for tenduke::oauth::OAuthStateServiceImpl:
tenduke::oauth::OAuthStateService tenduke::oauth::OAuthState

Public Member Functions

 OAuthStateServiceImpl (std::string accessToken, std::string refreshToken, int64_t expiresAt, bool infinite, std::map< std::string, std::string > additionalProperties, std::shared_ptr< const OAuthConfiguration > config, std::shared_ptr< const tenduke::http::HTTPClient > httpClient, std::shared_ptr< const tenduke::json::JSONParser > jsonParser, std::shared_ptr< tenduke::time::Clock > clock)
 Constructs new instance.
 
 OAuthStateServiceImpl (std::string accessToken, std::string refreshToken, int64_t expiresAt, std::map< std::string, std::string > additionalProperties, std::shared_ptr< const OAuthConfiguration > config, std::shared_ptr< const tenduke::http::HTTPClient > httpClient, std::shared_ptr< const tenduke::json::JSONParser > jsonParser, std::shared_ptr< tenduke::time::Clock > clock)
 Constructs new instance.
 
const std::string & getAccessToken () const override
 Returns the access token.
 
const std::string & getRefreshToken () const override
 Returns the refresh token.
 
int64_t getExpiresAt () const override
 Returns timestamp (as epoch seconds) when the current access token expires.
 
const std::string * getAdditionalProperty (const std::string &name) const override
 Returns additional property returned by the server.
 
bool hasAccessToken () const override
 Returns true if the state contains an access token.
 
bool doesExpire () const override
 Returns true if the access token expires.
 
bool isRefreshable () const override
 Returns true if the state is refreshable (i.e.
 
bool refresh () override
 Refresh the state, i.e.
 
- Public Member Functions inherited from tenduke::oauth::OAuthState
virtual const std::map< std::string, std::string > & getAdditionalProperties () const =0
 Returns all additional properties returned by the server.
 
virtual bool hasAdditionalProperty (const std::string &name) const =0
 Checks if the state has additional property.
 
virtual void removeAdditionalProperty (const std::string &propertyName)=0
 Removes given additional property.
 
virtual void setAccessToken (const std::string &newAccessToken)=0
 Set the access token.
 
virtual void setExpiresAt (std::int64_t newExpiresAt)=0
 Set the "expires at".
 
virtual void setRefreshToken (const std::string &newRefreshToken)=0
 Set the refresh token.
 
virtual void refreshFrom (const OAuthState &state)=0
 Refreshes the state from another state, This is called after refreshing the state with the service.
 

Protected Member Functions

virtual std::map< std::string, std::string > buildRefreshRequestParameters () const
 Builds parameters for refresh-request.
 
virtual std::unique_ptr< OAuthTokenRequestcreateRefreshTokenRequest () const
 Creates refresh-token request.
 

Constructor & Destructor Documentation

◆ OAuthStateServiceImpl() [1/2]

tenduke::oauth::OAuthStateServiceImpl::OAuthStateServiceImpl ( std::string  accessToken,
std::string  refreshToken,
int64_t  expiresAt,
bool  infinite,
std::map< std::string, std::string >  additionalProperties,
std::shared_ptr< const OAuthConfiguration config,
std::shared_ptr< const tenduke::http::HTTPClient httpClient,
std::shared_ptr< const tenduke::json::JSONParser jsonParser,
std::shared_ptr< tenduke::time::Clock clock 
)
inline

Constructs new instance.

Parameters
accessToken-
refreshToken-
expiresAt-
infinite-
additionalProperties-
config-
httpClient-
jsonParser-
clock-

◆ OAuthStateServiceImpl() [2/2]

tenduke::oauth::OAuthStateServiceImpl::OAuthStateServiceImpl ( std::string  accessToken,
std::string  refreshToken,
int64_t  expiresAt,
std::map< std::string, std::string >  additionalProperties,
std::shared_ptr< const OAuthConfiguration config,
std::shared_ptr< const tenduke::http::HTTPClient httpClient,
std::shared_ptr< const tenduke::json::JSONParser jsonParser,
std::shared_ptr< tenduke::time::Clock clock 
)
inline

Constructs new instance.

Parameters
accessToken-
refreshToken-
expiresAt-
additionalProperties-
config-
httpClient-
jsonParser-
clock-

Member Function Documentation

◆ buildRefreshRequestParameters()

std::map< std::string, std::string > tenduke::oauth::OAuthStateServiceImpl::buildRefreshRequestParameters ( ) const
protectedvirtual

Builds parameters for refresh-request.

Returns
-

◆ createRefreshTokenRequest()

std::unique_ptr< oauth::OAuthTokenRequest > tenduke::oauth::OAuthStateServiceImpl::createRefreshTokenRequest ( ) const
protectedvirtual

Creates refresh-token request.

Returns
-

◆ doesExpire()

bool tenduke::oauth::OAuthStateServiceImpl::doesExpire ( ) const
inlineoverridevirtual

Returns true if the access token expires.

Returns false if the access token does not expire.

Returns
-

Implements tenduke::oauth::OAuthState.

◆ getAccessToken()

const std::string & tenduke::oauth::OAuthStateServiceImpl::getAccessToken ( ) const
inlineoverridevirtual

Returns the access token.

Implements tenduke::oauth::OAuthState.

◆ getAdditionalProperty()

const std::string * tenduke::oauth::OAuthStateServiceImpl::getAdditionalProperty ( const std::string &  name) const
overridevirtual

Returns additional property returned by the server.

Parameters
nameproperty name
Returns
property value or nullptr if no such property

Implements tenduke::oauth::OAuthState.

◆ getExpiresAt()

int64_t tenduke::oauth::OAuthStateServiceImpl::getExpiresAt ( ) const
inlineoverridevirtual

Returns timestamp (as epoch seconds) when the current access token expires.

Returns
expiration of current accesstime in epoch seconds. Returns tenduke::oauth::TOKEN_DOES_NOT_EXPIRE if server did not return "expires_at".

Implements tenduke::oauth::OAuthState.

◆ getRefreshToken()

const std::string & tenduke::oauth::OAuthStateServiceImpl::getRefreshToken ( ) const
inlineoverridevirtual

Returns the refresh token.

Returns
the refresh-token. Returns empty string if no refresh token.

Implements tenduke::oauth::OAuthState.

◆ hasAccessToken()

bool tenduke::oauth::OAuthStateServiceImpl::hasAccessToken ( ) const
inlineoverridevirtual

Returns true if the state contains an access token.

(Uninitialized states do not contain access token).

Returns
-

Implements tenduke::oauth::OAuthState.

◆ isRefreshable()

bool tenduke::oauth::OAuthStateServiceImpl::isRefreshable ( ) const
inlineoverridevirtual

Returns true if the state is refreshable (i.e.

it contains refresh-token).

Returns
-

Implements tenduke::oauth::OAuthState.

◆ refresh()

bool tenduke::oauth::OAuthStateServiceImpl::refresh ( )
overridevirtual

Refresh the state, i.e.

requests new access token. The refresh is done synchronously.

Returns
true if refreshed. Returns false if nothing was done (because the state does not contain refresh token).
Exceptions
tenduke::oauth::OAuthServerExceptionwhen the server responds with an error
tenduke::oauth::OAuthExceptionwhen the server response is not what we expected, e.g.
  • The response does not contain access_token
  • The response payload is not JSON-object
tenduke::json::JSONParsingExceptionwhen response is not valid JSON
tenduke::net::NetworkingException(or subclasses of it) when networking error occurred, e.g.
tenduke::http::HTTPException(or subclasses of it) when the server responds with HTTP error status code which does not indicate OAuth-error, e.g. 500 (internal server error) or 404 (not found = wrong endpoint configured).

Implements tenduke::oauth::OAuthStateService.


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