10Duke Enterprise C++ SDK
Loading...
Searching...
No Matches
OAuthTokenRequest.h
1#ifndef TENDUKE_OAUTH_OAUTHTOKENREQUEST_H
2#define TENDUKE_OAUTH_OAUTHTOKENREQUEST_H
3
4#include "./OAuthTokenResponse.h"
5#include "http/HTTPCall.h"
6#include "http/HTTPClient.h"
7#include "http/HTTPResponseToException.h"
8#include "json/JSONObject.h"
9#include "json/JSONParser.h"
10#include "time/Clock.h"
11
12#include <memory>
13
14namespace tenduke { namespace oauth {
15
16
23{
24public:
26 static const std::int64_t MAX_EXPIRES_IN_S = 10LL * 365 * 24 * 60 * 60;
27
36 std::unique_ptr<tenduke::http::HTTPCall> httpCall,
37 const std::shared_ptr<const tenduke::json::JSONParser> &jsonParser,
38 const std::shared_ptr<tenduke::time::Clock> &clock,
39 const std::shared_ptr<const tenduke::http::HTTPResponseToException> &throwException
40 );
41
50 std::unique_ptr<tenduke::http::HTTPCall> httpCall,
51 const std::shared_ptr<const tenduke::json::JSONParser> &jsonParser,
52 const std::shared_ptr<tenduke::time::Clock> &clock
53 );
54
55 virtual ~OAuthTokenRequest() = default;
56
71 virtual std::unique_ptr<tenduke::oauth::OAuthTokenResponse> execute() const;
72
76 static std::unique_ptr<OAuthTokenRequest> create(
77 const std::string &tokenEndpointUrl,
78 const std::map<std::string, std::string> &parameters,
79 const std::shared_ptr<const tenduke::http::HTTPClient> &httpClient,
80 const std::shared_ptr<const tenduke::json::JSONParser> &jsonParser,
81 const std::shared_ptr<tenduke::time::Clock> &clock
82 );
83
84protected:
90 virtual std::unique_ptr<tenduke::json::JSONObject> parseResponseBody(const std::string &responsePayload) const;
91
97 virtual std::unique_ptr<tenduke::oauth::OAuthTokenResponse> toResponse(const std::string &responsePayload) const;
98
99private:
100 const std::unique_ptr<tenduke::http::HTTPCall> httpCall;
101 const std::shared_ptr<const tenduke::json::JSONParser> parseJSON;
102 const std::shared_ptr<const tenduke::time::Clock> clock;
103 const std::shared_ptr<const tenduke::http::HTTPResponseToException> throwException;
104};
105
106
107}}
108
109#endif // TENDUKE_OAUTH_OAUTHTOKENREQUEST_H
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.
Definition OAuthTokenRequest.cpp:25
virtual std::unique_ptr< tenduke::oauth::OAuthTokenResponse > toResponse(const std::string &responsePayload) const
Converts the response body to OAuthTokenResponse.
Definition OAuthTokenRequest.cpp:155
static std::unique_ptr< OAuthTokenRequest > create(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.
Definition OAuthTokenRequest.cpp:48
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.
Definition OAuthTokenRequest.cpp:25
virtual std::unique_ptr< tenduke::oauth::OAuthTokenResponse > execute() const
Executes the token request.
Definition OAuthTokenRequest.cpp:73
virtual std::unique_ptr< tenduke::json::JSONObject > parseResponseBody(const std::string &responsePayload) const
Parses the response body to JSON.
Definition OAuthTokenRequest.cpp:212
static const std::int64_t MAX_EXPIRES_IN_S
Maximum expires_in of a token response, 10 years: a larger value is limited to this.
Definition OAuthTokenRequest.h:26
OAuth services.
Definition AccessTokenRequestAuthenticator.h:8
Root for classes, functions and globals of 10Duke C++ Client.
Definition APIRequest.h:4