16 #ifndef ACSDKAUTHORIZATION_LWA_LWAAUTHORIZATIONADAPTER_H_ 17 #define ACSDKAUTHORIZATION_LWA_LWAAUTHORIZATIONADAPTER_H_ 19 #include <condition_variable> 34 namespace acsdkAuthorization {
49 ,
public std::enable_shared_from_this<LWAAuthorizationAdapter> {
65 static std::shared_ptr<LWAAuthorizationAdapter>
create(
66 const std::shared_ptr<avsCommon::utils::configuration::ConfigurationNode>& configuration,
67 std::unique_ptr<avsCommon::utils::libcurlUtils::HttpPostInterface> httpPost,
68 const std::shared_ptr<avsCommon::utils::DeviceInfo>& deviceInfo,
69 const std::shared_ptr<acsdkAuthorizationInterfaces::lwa::LWAAuthorizationStorageInterface>& storage,
70 std::unique_ptr<avsCommon::utils::libcurlUtils::HttpGetInterface> httpGet =
nullptr,
76 const std::shared_ptr<acsdkAuthorizationInterfaces::lwa::CBLAuthorizationObserverInterface>& observer)
override;
78 const std::shared_ptr<acsdkAuthorizationInterfaces::lwa::CBLAuthorizationObserverInterface>& observer)
override;
89 void reset()
override;
94 const std::shared_ptr<acsdkAuthorizationInterfaces::AuthorizationManagerInterface>& manager)
override;
99 enum class TokenExchangeMethod {
112 struct RefreshTokenResponse {
120 std::chrono::steady_clock::time_point requestTime;
123 std::chrono::seconds expiration;
129 bool isRefreshTokenVerified;
132 RefreshTokenResponse() :
135 requestTime{std::chrono::steady_clock::now()},
136 expiration{std::chrono::seconds::zero()},
137 isRefreshTokenVerified{
true} {
145 std::chrono::steady_clock::time_point getExpirationTime()
const {
146 return requestTime + expiration;
153 enum class FlowState {
191 std::unique_ptr<avsCommon::utils::libcurlUtils::HttpPostInterface> httpPost,
192 const std::shared_ptr<acsdkAuthorizationInterfaces::lwa::LWAAuthorizationStorageInterface>& storage,
193 std::unique_ptr<avsCommon::utils::libcurlUtils::HttpGetInterface> httpGet);
204 const std::shared_ptr<avsCommon::utils::DeviceInfo>& deviceInfo);
211 FlowState retrievePersistedData();
225 FlowState handleIdle();
232 FlowState handleRequestingToken();
239 FlowState handleRefreshingToken();
246 FlowState handleClearingData();
253 FlowState handleStopping();
260 void handleAuthorizationFlow(FlowState state);
264 bool authorizeUsingCBLHelper(
265 const std::shared_ptr<acsdkAuthorizationInterfaces::lwa::CBLAuthorizationObserverInterface>& observer,
266 bool requestCustomerProfile);
303 RefreshTokenResponse* tokenResponse);
324 bool expiresImmediately,
325 struct RefreshTokenResponse* tokenResponse);
332 bool shouldStopRetrying();
340 bool shouldStopRetryingLocked();
347 bool isShuttingDown();
358 void resetAuthMethodLocked();
366 void setRefreshTokenResponse(
const RefreshTokenResponse& response,
bool persist =
true);
375 void setRefreshTokenResponseLocked(
const RefreshTokenResponse& response,
bool persist =
true);
383 void updateStateAndNotifyManager(
394 bool getCustomerProfile(
const std::string& accessToken);
403 std::unique_ptr<avsCommon::utils::libcurlUtils::HttpPostInterface> m_httpPost;
409 std::unique_ptr<avsCommon::utils::libcurlUtils::HttpGetInterface> m_httpGet;
412 std::shared_ptr<acsdkAuthorizationInterfaces::lwa::LWAAuthorizationStorageInterface> m_storage;
415 std::unique_ptr<LWAAuthorizationConfiguration> m_configuration;
427 std::condition_variable m_wake;
430 std::thread m_authorizationFlowThread;
435 std::chrono::steady_clock::time_point m_codePairExpirationTime;
444 std::chrono::seconds m_tokenRequestInterval;
447 std::shared_ptr<acsdkAuthorizationInterfaces::lwa::CBLAuthorizationObserverInterface> m_cblRequester;
450 bool m_requestCustomerProfile;
454 bool m_authFailureReported;
457 TokenExchangeMethod m_authMethod;
460 RefreshTokenResponse m_refreshTokenResponse;
463 std::shared_ptr<acsdkAuthorizationInterfaces::AuthorizationManagerInterface> m_manager;
466 bool m_isShuttingDown;
469 bool m_isClearingData;
479 #endif // ACSDKAUTHORIZATION_LWA_LWAAUTHORIZATIONADAPTER_H_ Definition: ConfigurationNode.h:71
Definition: LWAAuthorizationInterface.h:31
std::string getId() override
bool authorizeUsingCBLWithCustomerProfile(const std::shared_ptr< acsdkAuthorizationInterfaces::lwa::CBLAuthorizationObserverInterface > &observer) override
::std::string string
Definition: gtest-port.h:1097
static std::shared_ptr< LWAAuthorizationAdapter > create(const std::shared_ptr< avsCommon::utils::configuration::ConfigurationNode > &configuration, std::unique_ptr< avsCommon::utils::libcurlUtils::HttpPostInterface > httpPost, const std::shared_ptr< avsCommon::utils::DeviceInfo > &deviceInfo, const std::shared_ptr< acsdkAuthorizationInterfaces::lwa::LWAAuthorizationStorageInterface > &storage, std::unique_ptr< avsCommon::utils::libcurlUtils::HttpGetInterface > httpGet=nullptr, const std::string &adapterId="")
Definition: AuthorizationAdapterInterface.h:42
State
The enum State describes the state of authorization.
Definition: AuthObserverInterface.h:34
avsCommon::sdkInterfaces::AuthObserverInterface::FullState onAuthorizationManagerReady(const std::shared_ptr< acsdkAuthorizationInterfaces::AuthorizationManagerInterface > &manager) override
Definition: LWAAuthorizationAdapter.h:46
Definition: Optional.h:32
Definition: HTTPResponse.h:29
std::string getAuthToken() override
An aggregated structure to simplify working with State and Error.
Definition: AuthObserverInterface.h:80
bool authorizeUsingCBL(const std::shared_ptr< acsdkAuthorizationInterfaces::lwa::CBLAuthorizationObserverInterface > &observer) override
Error
The enum Error encodes possible errors which may occur when changing state.
Definition: AuthObserverInterface.h:48
Whether or not curl logs should be emitted.
Definition: AVSConnectionManager.h:36
std::shared_ptr< acsdkAuthorizationInterfaces::AuthorizationInterface > getAuthorizationInterface() override
void onAuthFailure(const std::string &authToken) override
avsCommon::sdkInterfaces::AuthObserverInterface::FullState getState() override
~LWAAuthorizationAdapter()
Destructor.