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

#include <OAuthTokenRequest.h>

Detailed Description

OAuth token request.

Performs both "exchange-code-to-accesstoken" and "refresh token" requests. Used mostly internally to share common functionality.

Inheritance diagram for tenduke::oauth::OAuthTokenRequest:
tenduke::test::mocks::OAuthTokenRequestFake

Public Member Functions

 OAuthTokenRequest (std::unique_ptr< tenduke::http::HTTPCall > httpCall, const std::shared_ptr< const tenduke::json::JSONParser > &jsonParser, const std::shared_ptr< tenduke::time::Clock > &clock, const std::shared_ptr< const tenduke::http::HTTPResponseToException > &throwException)
 Constructs new instance.
 
 OAuthTokenRequest (std::unique_ptr< tenduke::http::HTTPCall > httpCall, const std::shared_ptr< const tenduke::json::JSONParser > &jsonParser, const std::shared_ptr< tenduke::time::Clock > &clock)
 Constructs new instance.
 
virtual std::unique_ptr< tenduke::oauth::OAuthTokenResponseexecute () const
 Executes the token request.
 

Static Public Member Functions

static std::unique_ptr< OAuthTokenRequestcreate (const std::string &tokenEndpointUrl, const std::map< std::string, std::string > &parameters, const std::shared_ptr< const tenduke::http::HTTPClient > &httpClient, const std::shared_ptr< const tenduke::json::JSONParser > &jsonParser, const std::shared_ptr< tenduke::time::Clock > &clock)
 Factory method to create the request.
 

Protected Member Functions

virtual std::unique_ptr< tenduke::json::JSONObjectparseResponseBody (const std::string &responsePayload) const
 Parses the response body to JSON.
 
virtual std::unique_ptr< tenduke::oauth::OAuthTokenResponsetoResponse (const std::string &responsePayload) const
 Converts the response body to OAuthTokenResponse.
 

Constructor & Destructor Documentation

◆ OAuthTokenRequest() [1/2]

tenduke::oauth::OAuthTokenRequest::OAuthTokenRequest ( std::unique_ptr< tenduke::http::HTTPCall httpCall,
const std::shared_ptr< const tenduke::json::JSONParser > &  jsonParser,
const std::shared_ptr< tenduke::time::Clock > &  clock,
const std::shared_ptr< const tenduke::http::HTTPResponseToException > &  throwException 
)

Constructs new instance.

Parameters
httpCallthe HTTP call to be executed
jsonParserFor parsing the the response
clockfor generating "expires-at" from "expires-in"
throwExceptionmaps HTTP status codes to exceptions

◆ OAuthTokenRequest() [2/2]

tenduke::oauth::OAuthTokenRequest::OAuthTokenRequest ( std::unique_ptr< tenduke::http::HTTPCall httpCall,
const std::shared_ptr< const tenduke::json::JSONParser > &  jsonParser,
const std::shared_ptr< tenduke::time::Clock > &  clock 
)

Constructs new instance.

Uses default implementation for "throwException".

Parameters
httpCallthe HTTP call to be executed
jsonParserFor parsing the the response
clockfor generating "expires-at" from "expires-in"

Member Function Documentation

◆ execute()

std::unique_ptr< xdoauth::OAuthTokenResponse > tenduke::oauth::OAuthTokenRequest::execute ( ) const
virtual

Executes the token request.

Exceptions
tenduke::oauth::OAuthServerErrorwhen 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).
std::nested_exceptionwhen the there is some nested cause

Reimplemented in tenduke::test::mocks::OAuthTokenRequestFake.

◆ parseResponseBody()

std::unique_ptr< xdjson::JSONObject > tenduke::oauth::OAuthTokenRequest::parseResponseBody ( const std::string &  responsePayload) const
protectedvirtual

Parses the response body to JSON.

Parameters
responsePayload-
Returns
-

◆ toResponse()

std::unique_ptr< xdoauth::OAuthTokenResponse > tenduke::oauth::OAuthTokenRequest::toResponse ( const std::string &  responsePayload) const
protectedvirtual

Converts the response body to OAuthTokenResponse.

Parameters
responsePayload-
Returns
-

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