10Duke Enterprise C++ SDK
Loading...
Searching...
No Matches
DefaultOAuthDeviceFlowAuthorizationRequest.h
1#ifndef TENDUKE_OAUTH_DEVICE_DEFAULTOAUTHDEVICEFLOWAUTHORIZATIONREQUEST_H
2#define TENDUKE_OAUTH_DEVICE_DEFAULTOAUTHDEVICEFLOWAUTHORIZATIONREQUEST_H
3
4#include "./OAuthDeviceFlowAuthorizationRequest.h"
5#include "./DeviceAuthorizationResponse.h"
6#include "oauth/OAuthConfiguration.h"
7#include "oauth/OAuthState.h"
8
9#include "http/HTTPClient.h"
10#include "http/HTTPResponseToException.h"
11#include "json/JSONParser.h"
12#include "time/Clock.h"
13
14#include <chrono>
15#include <condition_variable>
16#include <cstdint>
17#include <map>
18#include <memory>
19#include <mutex>
20#include <string>
21
22namespace tenduke { namespace oauth { namespace device {
23
24
29{
30public:
43 std::string scope,
44 const std::map<std::string, std::string> &additionalParameters,
45 std::uint64_t timeoutS,
46 const std::shared_ptr<const tenduke::oauth::OAuthConfiguration> &configuration,
47 const std::shared_ptr<tenduke::time::Clock> &clock,
48 const std::shared_ptr<const tenduke::http::HTTPClient> &httpClient,
49 const std::shared_ptr<const tenduke::http::HTTPResponseToException> &throwException,
50 const std::shared_ptr<const tenduke::json::JSONParser> &jsonParser
51 );
52
53 // `tenduke::oauth::device::OAuthDeviceFlowAuthorizationRequest` interface
54public:
56 std::unique_ptr<tenduke::oauth::OAuthState> accessTokenRequest() override;
57 void cancel() override;
58
59protected:
64 virtual void sleepFor(std::chrono::milliseconds slumbertime);
65
66private:
68 void throwIfCanceled(const std::string &where) const;
69
70 const std::string scope;
71 const std::map<std::string, std::string> additionalParameters;
72 const std::uint64_t timeoutS;
73
74 // cancel() is called from another thread than the polling: canceled is protected by cancelMutex, and
75 // cancelSignal wakes up sleepFor()
76 mutable std::mutex cancelMutex;
77 std::condition_variable cancelSignal;
78 bool canceled;
79
80 // state: if nullptr, response has not been received
81 std::unique_ptr<tenduke::oauth::device::DeviceAuthorizationResponse> response;
82
83 const std::shared_ptr<const tenduke::oauth::OAuthConfiguration> configuration;
84 const std::shared_ptr<tenduke::time::Clock> clock;
85 const std::shared_ptr<const tenduke::http::HTTPClient> http;
86 const std::shared_ptr<const tenduke::http::HTTPResponseToException> throwException;
87 const std::shared_ptr<const tenduke::json::JSONParser> parseJSON;
88};
89
90}}}
91
92#endif // TENDUKE_OAUTH_DEVICE_DEFAULTOAUTHDEVICEFLOWAUTHORIZATIONREQUEST_H
DefaultOAuthDeviceFlowAuthorizationRequest(std::string scope, const std::map< std::string, std::string > &additionalParameters, std::uint64_t timeoutS, const std::shared_ptr< const tenduke::oauth::OAuthConfiguration > &configuration, const std::shared_ptr< tenduke::time::Clock > &clock, const std::shared_ptr< const tenduke::http::HTTPClient > &httpClient, const std::shared_ptr< const tenduke::http::HTTPResponseToException > &throwException, const std::shared_ptr< const tenduke::json::JSONParser > &jsonParser)
Constructs new instance.
Definition DefaultOAuthDeviceFlowAuthorizationRequest.cpp:345
DefaultOAuthDeviceFlowAuthorizationRequest(std::string scope, const std::map< std::string, std::string > &additionalParameters, std::uint64_t timeoutS, const std::shared_ptr< const tenduke::oauth::OAuthConfiguration > &configuration, const std::shared_ptr< tenduke::time::Clock > &clock, const std::shared_ptr< const tenduke::http::HTTPClient > &httpClient, const std::shared_ptr< const tenduke::http::HTTPResponseToException > &throwException, const std::shared_ptr< const tenduke::json::JSONParser > &jsonParser)
Constructs new instance.
Definition DefaultOAuthDeviceFlowAuthorizationRequest.cpp:345
virtual void sleepFor(std::chrono::milliseconds slumbertime)
Sleeps for given time, or until cancel() is called.
Definition DefaultOAuthDeviceFlowAuthorizationRequest.cpp:329
tenduke::oauth::device::DeviceAuthorizationResponse authorizationRequest() override
Performs Device Authorization Request.
Definition DefaultOAuthDeviceFlowAuthorizationRequest.cpp:174
std::unique_ptr< tenduke::oauth::OAuthState > accessTokenRequest() override
Performs Device Access Token Request.
Definition DefaultOAuthDeviceFlowAuthorizationRequest.cpp:238
void cancel() override
Marks the request canceled.
Definition DefaultOAuthDeviceFlowAuthorizationRequest.cpp:320
Device Authorization Response.
Definition DeviceAuthorizationResponse.h:23
Authorization request for OAuth Device Flow.
Definition OAuthDeviceFlowAuthorizationRequest.h:23
Implementation of OAuth device flow.
Definition DefaultOAuthDeviceFlow.h:18
OAuth services.
Definition AccessTokenRequestAuthenticator.h:8
Root for classes, functions and globals of 10Duke C++ Client.
Definition APIRequest.h:4