16 #ifndef CBLAUTHDELEGATE_CBLAUTHDELEGATE_H_ 17 #define CBLAUTHDELEGATE_CBLAUTHDELEGATE_H_ 20 #include <condition_variable> 25 #include <unordered_set> 36 #include "CBLAuthDelegate/CBLAuthDelegateStorageInterface.h" 37 #include "CBLAuthDelegate/CBLAuthRequesterInterface.h" 40 namespace authorization {
41 namespace cblAuthDelegate {
70 const std::shared_ptr<avsCommon::utils::configuration::ConfigurationNode>& configuration,
71 const std::shared_ptr<registrationManager::CustomerDataManagerInterface>& customerDataManager,
72 const std::shared_ptr<CBLAuthDelegateStorageInterface>& storage,
73 const std::shared_ptr<CBLAuthRequesterInterface>& authRequester,
74 std::unique_ptr<avsCommon::utils::libcurlUtils::HttpPostInterface> httpPost,
75 const std::shared_ptr<avsCommon::utils::DeviceInfo>& deviceInfo);
95 static std::unique_ptr<CBLAuthDelegate>
create(
97 std::shared_ptr<registrationManager::CustomerDataManagerInterface> customerDataManager,
98 std::shared_ptr<CBLAuthDelegateStorageInterface> storage,
99 std::shared_ptr<CBLAuthRequesterInterface> authRequester,
100 std::shared_ptr<avsCommon::utils::libcurlUtils::HttpPostInterface> httpPost =
nullptr,
101 std::shared_ptr<avsCommon::utils::DeviceInfo> deviceInfo =
nullptr);
124 void addAuthObserver(std::shared_ptr<avsCommon::sdkInterfaces::AuthObserverInterface> observer)
override;
125 void removeAuthObserver(std::shared_ptr<avsCommon::sdkInterfaces::AuthObserverInterface> observer)
override;
140 enum class FlowState {
148 REQUESTING_CODE_PAIR,
175 std::shared_ptr<registrationManager::CustomerDataManagerInterface> customerDataManager,
176 std::shared_ptr<CBLAuthDelegateStorageInterface> storage,
177 std::shared_ptr<CBLAuthRequesterInterface> authRequester,
178 std::shared_ptr<avsCommon::utils::libcurlUtils::HttpPostInterface> httpPost);
190 const std::shared_ptr<avsCommon::utils::DeviceInfo>& deviceInfo);
200 void handleAuthorizationFlow();
207 FlowState handleStarting();
214 FlowState handleRequestingCodePair();
221 FlowState handleRequestingToken();
228 FlowState handleRefreshingToken();
235 FlowState handleStopping();
279 bool expiresImmediately);
300 void setRefreshToken(
const std::string& refreshToken);
305 void clearRefreshToken();
318 std::shared_ptr<CBLAuthDelegateStorageInterface> m_storage;
324 std::shared_ptr<avsCommon::utils::libcurlUtils::HttpPostInterface> m_httpPost;
327 std::shared_ptr<CBLAuthRequesterInterface> m_authRequester;
330 std::unique_ptr<acsdkAuthorization::lwa::LWAAuthorizationConfiguration> m_configuration;
339 std::unordered_set<std::shared_ptr<avsCommon::sdkInterfaces::AuthObserverInterface>> m_observers;
357 std::thread m_authorizationFlowThread;
360 std::chrono::steady_clock::time_point m_codePairExpirationTime;
363 std::chrono::steady_clock::time_point m_tokenExpirationTime;
369 std::condition_variable m_wake;
372 std::chrono::steady_clock::time_point m_timeToRefresh;
375 std::chrono::steady_clock::time_point m_requestTime;
381 bool m_newRefreshToken;
384 bool m_authFailureReported;
391 #endif // CBLAUTHDELEGATE_CBLAUTHDELEGATE_H_ Definition: ConfigurationNode.h:71
std::string getAuthToken() override
void onAuthFailure(const std::string &token) override
void addAuthObserver(std::shared_ptr< avsCommon::sdkInterfaces::AuthObserverInterface > observer) override
Definition: CBLAuthDelegate.h:48
::std::string string
Definition: gtest-port.h:1097
CBLAuthDelegate(const CBLAuthDelegate &rhs)=delete
State
The enum State describes the state of authorization.
Definition: AuthObserverInterface.h:34
static std::unique_ptr< CBLAuthDelegate > create(const avsCommon::utils::configuration::ConfigurationNode &configuration, std::shared_ptr< registrationManager::CustomerDataManagerInterface > customerDataManager, std::shared_ptr< CBLAuthDelegateStorageInterface > storage, std::shared_ptr< CBLAuthRequesterInterface > authRequester, std::shared_ptr< avsCommon::utils::libcurlUtils::HttpPostInterface > httpPost=nullptr, std::shared_ptr< avsCommon::utils::DeviceInfo > deviceInfo=nullptr)
CBLAuthDelegate & operator=(const CBLAuthDelegate &rhs)=delete
Definition: HTTPResponse.h:29
Definition: AuthDelegateInterface.h:40
Error
The enum Error encodes possible errors which may occur when changing state.
Definition: AuthObserverInterface.h:48
void removeAuthObserver(std::shared_ptr< avsCommon::sdkInterfaces::AuthObserverInterface > observer) override
Whether or not curl logs should be emitted.
Definition: AVSConnectionManager.h:36
static std::shared_ptr< AuthDelegateInterface > createAuthDelegateInterface(const std::shared_ptr< avsCommon::utils::configuration::ConfigurationNode > &configuration, const std::shared_ptr< registrationManager::CustomerDataManagerInterface > &customerDataManager, const std::shared_ptr< CBLAuthDelegateStorageInterface > &storage, const std::shared_ptr< CBLAuthRequesterInterface > &authRequester, std::unique_ptr< avsCommon::utils::libcurlUtils::HttpPostInterface > httpPost, const std::shared_ptr< avsCommon::utils::DeviceInfo > &deviceInfo)
Definition: CustomerDataHandler.h:34
void clearData() override