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

#include <OAuthPKCERequest.h>

Detailed Description

PKCE-implementation of tenduke::oauth::OAuthRequest.

Inheritance diagram for tenduke::oauth::pkce::OAuthPKCERequest:
tenduke::oauth::OAuthBrowserAuthorizationRequest tenduke::oauth::OAuthAuthorizationRequest

Public Member Functions

 OAuthPKCERequest (std::string scopes, std::string state, std::map< std::string, std::string > additionalParameters, std::string codeVerifier, std::shared_ptr< const tenduke::oauth::OAuthConfiguration > config, std::shared_ptr< const tenduke::http::HTTPClient > httpClient, std::shared_ptr< const tenduke::net::URLParser > urlParser, std::shared_ptr< const tenduke::json::JSONParser > jsonParser, std::shared_ptr< const tenduke::utl::Base64Encoder > base64Encoder, std::shared_ptr< const tenduke::crypto::MessageDigestFactory > messageDigestFactory, std::shared_ptr< tenduke::time::Clock > clock)
 Constructs new instance.
 
std::string buildAuthorizationRequestUrl () const override
 Creates the initial authorization request URL.
 
std::unique_ptr< tenduke::oauth::OAuthStatehandleCallback (const std::string &redirectUri) const override
 Handles callback: performs consequent actions to authorize.
 

Protected Member Functions

virtual std::map< std::string, std::string > buildTokenRequestParameters (const std::string &code) const
 Builds parameters for the token request.
 
virtual std::map< std::string, std::string > buildAuthorizationRequestParameters () const
 Builds parameters for the authorization request.
 
virtual void createCodeChallenge (std::map< std::string, std::string > &parameters) const
 Creates PKCE code challenge and adds it to the provided parameters.
 
virtual std::unique_ptr< tenduke::oauth::OAuthStatehandleSuccessfulCallback (const std::multimap< std::string, std::string > &queryParameters) const
 Handles successful callback to redirect-uri from authorization request, performing the next steps to complete the authorization.
 
virtual std::unique_ptr< tenduke::oauth::OAuthStatehandleTokenResponse (std::unique_ptr< tenduke::oauth::OAuthTokenResponse > response) const
 Handles token response.
 
virtual bool isPKCERequest () const
 Checks if this is PKCE-request.
 
virtual std::unique_ptr< tenduke::oauth::OAuthTokenRequestcreateTokenRequest (const std::string &code) const
 Creates the token request.
 

Constructor & Destructor Documentation

◆ OAuthPKCERequest()

tenduke::oauth::pkce::OAuthPKCERequest::OAuthPKCERequest ( std::string  scopes,
std::string  state,
std::map< std::string, std::string >  additionalParameters,
std::string  codeVerifier,
std::shared_ptr< const tenduke::oauth::OAuthConfiguration config,
std::shared_ptr< const tenduke::http::HTTPClient httpClient,
std::shared_ptr< const tenduke::net::URLParser urlParser,
std::shared_ptr< const tenduke::json::JSONParser jsonParser,
std::shared_ptr< const tenduke::utl::Base64Encoder base64Encoder,
std::shared_ptr< const tenduke::crypto::MessageDigestFactory messageDigestFactory,
std::shared_ptr< tenduke::time::Clock clock 
)

Constructs new instance.

Parameters
scopes-
state-
additionalParameters-
codeVerifier-
config-
httpClient-
urlParser-
jsonParser-
base64Encoder-
messageDigestFactory-
clock-

Member Function Documentation

◆ buildAuthorizationRequestParameters()

std::map< std::string, std::string > tenduke::oauth::pkce::OAuthPKCERequest::buildAuthorizationRequestParameters ( ) const
protectedvirtual

Builds parameters for the authorization request.

Returns
authorization request parameters

◆ buildAuthorizationRequestUrl()

std::string tenduke::oauth::pkce::OAuthPKCERequest::buildAuthorizationRequestUrl ( ) const
overridevirtual

Creates the initial authorization request URL.

Navigate browser to this URL.

Implements tenduke::oauth::OAuthBrowserAuthorizationRequest.

◆ buildTokenRequestParameters()

std::map< std::string, std::string > tenduke::oauth::pkce::OAuthPKCERequest::buildTokenRequestParameters ( const std::string &  code) const
protectedvirtual

Builds parameters for the token request.

Parameters
codeauthorization code returned from the authorization request.
Returns
token request parameters

◆ createCodeChallenge()

void tenduke::oauth::pkce::OAuthPKCERequest::createCodeChallenge ( std::map< std::string, std::string > &  parameters) const
protectedvirtual

Creates PKCE code challenge and adds it to the provided parameters.

Parameters
parameters-

◆ createTokenRequest()

std::unique_ptr<::OAuthTokenRequest > tenduke::oauth::pkce::OAuthPKCERequest::createTokenRequest ( const std::string &  code) const
protectedvirtual

Creates the token request.

Parameters
codeauthorization code returned from the authorization request.
Returns
the token request.

◆ handleCallback()

std::unique_ptr<::OAuthState > tenduke::oauth::pkce::OAuthPKCERequest::handleCallback ( const std::string &  redirectURI) const
overridevirtual

Handles callback: performs consequent actions to authorize.

In the flow, the OAuth-server signals success or error by navigating (using HTTP-redirect) to configured redirect-URI. You must listen the browser events to detect, when the redirect-URI is navigated to. Once you detect navigation to the redirect-URI, call this method with the complete redirect-URI.

The call is synchronous.

Parameters
redirectURI-
Returns
the OAuth-state
Exceptions
std::nested_exceptionwhen the there is some nested cause
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)
tenduke::json::JSONParsingExceptionwhen server response is not valid JSON
tenduke::oauth::OAuthExceptionwhen the server response is not what we expected, e.g.
  • problems with the redirect-URI (missing or invalid "state", missing "code")
  • The token response does not contain access_token
  • The token response payload is not JSON-object
tenduke::oauth::OAuthServerErrorwhen the server responds with an error
tenduke::net::NetworkingException(or subclasses of it) when networking error occurred, e.g.
tenduke::net::URLExceptionif problem parsing the redirectURI (should not happen, though)
tenduke::net::MalformedURLExceptionif the redirectURI is invalid

Implements tenduke::oauth::OAuthBrowserAuthorizationRequest.

◆ handleSuccessfulCallback()

std::unique_ptr<::OAuthState > tenduke::oauth::pkce::OAuthPKCERequest::handleSuccessfulCallback ( const std::multimap< std::string, std::string > &  queryParameters) const
protectedvirtual

Handles successful callback to redirect-uri from authorization request, performing the next steps to complete the authorization.

Parameters
queryParametersquery parameters extracted from the callback to the redirect-uri
Returns
the new state

◆ handleTokenResponse()

std::unique_ptr<::OAuthState > tenduke::oauth::pkce::OAuthPKCERequest::handleTokenResponse ( std::unique_ptr< tenduke::oauth::OAuthTokenResponse response) const
protectedvirtual

Handles token response.

Parameters
responsethe token response
Returns
the new state

◆ isPKCERequest()

bool tenduke::oauth::pkce::OAuthPKCERequest::isPKCERequest ( ) const
protectedvirtual

Checks if this is PKCE-request.

Returns
-

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