AlexaClientSDK  3.0.0
A cross-platform, modular SDK for interacting with the Alexa Voice Service
Public Member Functions | Static Public Member Functions | List of all members
alexaClientSDK::acsdkAuthorization::AuthorizationManager Class Reference

#include <AuthorizationManager.h>

Inheritance diagram for alexaClientSDK::acsdkAuthorization::AuthorizationManager:
Inheritance graph
[legend]
Collaboration diagram for alexaClientSDK::acsdkAuthorization::AuthorizationManager:
Collaboration graph
[legend]

Public Member Functions

void setRegistrationManager (const std::shared_ptr< registrationManager::RegistrationManagerInterface > registrationManager)
 
AuthorizationManagerInterface Functions
void reportStateChange (const avsCommon::sdkInterfaces::AuthObserverInterface::FullState &state, const std::string &authId, const std::string &userId) override
 
void add (const std::shared_ptr< acsdkAuthorizationInterfaces::AuthorizationAdapterInterface > &adapter) override
 
AuthorizationAuthorityInterface Functions
void logout () override
 
avsCommon::sdkInterfaces::AuthObserverInterface::State getState () override
 
std::string getActiveAuthorization () override
 
AuthDelegateInterface Functions
void addAuthObserver (std::shared_ptr< avsCommon::sdkInterfaces::AuthObserverInterface > observer) override
 
void removeAuthObserver (std::shared_ptr< avsCommon::sdkInterfaces::AuthObserverInterface > observer) override
 
std::string getAuthToken () override
 
void onAuthFailure (const std::string &token) override
 
CustomerDataHandler Functions
void clearData () override
 
void doShutdown () override
 
- Public Member Functions inherited from alexaClientSDK::acsdkAuthorizationInterfaces::AuthorizationManagerInterface
virtual ~AuthorizationManagerInterface ()=default
 Destructor. More...
 
virtual void add (const std::shared_ptr< acsdkAuthorizationInterfaces::AuthorizationAdapterInterface > &adapter)=0
 
- Public Member Functions inherited from alexaClientSDK::acsdkAuthorizationInterfaces::AuthorizationAuthorityInterface
virtual ~AuthorizationAuthorityInterface ()=default
 Destructor. More...
 
- Public Member Functions inherited from alexaClientSDK::avsCommon::sdkInterfaces::AuthDelegateInterface
virtual ~AuthDelegateInterface ()=default
 
virtual void addAuthObserver (std::shared_ptr< avsCommon::sdkInterfaces::AuthObserverInterface > observer)=0
 
virtual void removeAuthObserver (std::shared_ptr< avsCommon::sdkInterfaces::AuthObserverInterface > observer)=0
 
- Public Member Functions inherited from alexaClientSDK::registrationManager::RegistrationManagerInterface
virtual ~RegistrationManagerInterface ()=default
 
- Public Member Functions inherited from alexaClientSDK::avsCommon::utils::RequiresShutdown
 RequiresShutdown (const std::string &name)
 
virtual ~RequiresShutdown ()
 Destructor. More...
 
const std::string & name () const
 
void shutdown ()
 
bool isShutdown () const
 
- Public Member Functions inherited from alexaClientSDK::registrationManager::CustomerDataHandler
 CustomerDataHandler (const std::shared_ptr< registrationManager::CustomerDataManagerInterface > &dataManager)
 
virtual ~CustomerDataHandler ()
 
- Public Member Functions inherited from alexaClientSDK::registrationManager::CustomerDataHandlerInterface
virtual ~CustomerDataHandlerInterface ()=default
 

Static Public Member Functions

static std::shared_ptr< acsdkAuthorization::AuthorizationManagercreate (const std::shared_ptr< avsCommon::sdkInterfaces::storage::MiscStorageInterface > &storage, const std::shared_ptr< registrationManager::CustomerDataManagerInterface > &customerDataManager)
 

Additional Inherited Members

Detailed Description

This class allows for runtime switching between different authorization mechanisms. It implements the following interfaces:

To integrate an AuthorizationAdapterInterface with this class, first it must be added via the AuthorizationManagerInterface::add method. Then, adapters can report state changes via AuthorizationManagerInterface::reportStateChange. When reporting state, the unique identifer for the adapter must be sent. Additionally, it is advised to attach a userId that represents the customer. This is currently optional, but allows for strong protection of customer data. AuthorizationManager will initiate a logout in cases where ids mismatch.

Logout:

AuthorizationAdapterInterface instances should not extend CustomerDataHandler. Instead, expect an AuthorizationAdapterInterface::reset for when persisted user data should be cleared.

States:

AuthObserverInterface::State::UNINITIALIZED

This is an uninitialized state.

AuthObserverInterface::State::AUTHORIZING

Upon first authorization, the state must be reported. This tells AuthorizationManager that a new authorization is occuring, and will be used for future token requests once AuthObserverInterface::State::REFRESHED is reported.

Implicit Logout: For convenience, when switching between authorizations, a non-active adapter can force logout by sending a reportStateChange with AuthObserverInterface::State::AUTHORIZING. This will signal to the AuthorizationManager that a new adapter wishes to authorize, and implicitly log the system out.

AuthObserverInterface::State::REFRESHED

This state indicates a successful authorization, and indicates the AuthorizationManager will respond to getAuthToken() requests by querying the adapter. Sending this with a non-active authorization will cause a logout. This restriction is to ensure authorization state consistency is maintained and that customer data is protected. The active adapter's id and user id is persisted and will be used to validate future reportStateChange calls.

AuthObserverInterface::State::EXPIRED

This state indicates the token has expired.

AuthObserverItnerface::State::UNRECOVERABLE_ERROR

This should be reserved for unrecoverable errors, and will cause AuthorizationManager to force a logout.

AuthorizationManager currently implements CustomDataHandler and subscribes itself to RegistrationManager. This is because RegistrationManager still acts as the main implementation of RegistrationManagerInterface in the AVS SDK.

Member Function Documentation

◆ add()

void alexaClientSDK::acsdkAuthorization::AuthorizationManager::add ( const std::shared_ptr< acsdkAuthorizationInterfaces::AuthorizationAdapterInterface > &  adapter)
override

◆ addAuthObserver()

void alexaClientSDK::acsdkAuthorization::AuthorizationManager::addAuthObserver ( std::shared_ptr< avsCommon::sdkInterfaces::AuthObserverInterface observer)
override

◆ clearData()

void alexaClientSDK::acsdkAuthorization::AuthorizationManager::clearData ( )
overridevirtual

Reset any internal state that may be associated with a particular user.

Warning
Object must succeed in deleting any customer data.
This method is called while CustomerDataManager is in a locked state. Do not call or wait for any CustomerDataManager operation.

Implements alexaClientSDK::registrationManager::CustomerDataHandlerInterface.

◆ create()

static std::shared_ptr<acsdkAuthorization::AuthorizationManager> alexaClientSDK::acsdkAuthorization::AuthorizationManager::create ( const std::shared_ptr< avsCommon::sdkInterfaces::storage::MiscStorageInterface > &  storage,
const std::shared_ptr< registrationManager::CustomerDataManagerInterface > &  customerDataManager 
)
static

Creates an instance of AuthorizationManager.

Parameters
storageThe storage interface.
customerDataManagerA CustomerDataManagerInterface instance to initiate logout.
Returns
AuthorizationManager. Will return a nullptr if creation fails.

◆ doShutdown()

void alexaClientSDK::acsdkAuthorization::AuthorizationManager::doShutdown ( )
overridevirtual

Prepares/enables this object to be deleted. This should be the last function called on this object prior to deleting (or resetting) its shared_ptr.

Warning
  • Attempting to call functions on this object after calling shutdown() can result in undefined behavior.
  • Neglecting to call shutdown() on this object can result in resource leaks or other undefined behavior.

Implements alexaClientSDK::avsCommon::utils::RequiresShutdown.

◆ getActiveAuthorization()

std::string alexaClientSDK::acsdkAuthorization::AuthorizationManager::getActiveAuthorization ( )
overridevirtual

Returns the string identifying the current active AuthorizationInterface. An active adapter can be in the process of obtaining authorization tokens.

Returns
The active authorization.

Implements alexaClientSDK::acsdkAuthorizationInterfaces::AuthorizationAuthorityInterface.

◆ getAuthToken()

std::string alexaClientSDK::acsdkAuthorization::AuthorizationManager::getAuthToken ( )
overridevirtual

Get the current LWA authorization token.

Returns
The current authorization token. The returned value will be empty if an authorization token has yet to be acquired or if the most recently acquired token has expired.

Implements alexaClientSDK::avsCommon::sdkInterfaces::AuthDelegateInterface.

◆ getState()

avsCommon::sdkInterfaces::AuthObserverInterface::State alexaClientSDK::acsdkAuthorization::AuthorizationManager::getState ( )
overridevirtual

Returns the current authorization state.

Returns
The current authorization state.

Implements alexaClientSDK::acsdkAuthorizationInterfaces::AuthorizationAuthorityInterface.

◆ logout()

void alexaClientSDK::acsdkAuthorization::AuthorizationManager::logout ( )
overridevirtual

Log out current customer. This will clear any persistent data.

Implements alexaClientSDK::registrationManager::RegistrationManagerInterface.

◆ onAuthFailure()

void alexaClientSDK::acsdkAuthorization::AuthorizationManager::onAuthFailure ( const std::string &  token)
overridevirtual

Receive notification that an operation using the specified auth token experienced an authorization failure.

Parameters
tokenThe token used to authorize the forbidden operation.

Implements alexaClientSDK::avsCommon::sdkInterfaces::AuthDelegateInterface.

◆ removeAuthObserver()

void alexaClientSDK::acsdkAuthorization::AuthorizationManager::removeAuthObserver ( std::shared_ptr< avsCommon::sdkInterfaces::AuthObserverInterface observer)
override

◆ reportStateChange()

void alexaClientSDK::acsdkAuthorization::AuthorizationManager::reportStateChange ( const avsCommon::sdkInterfaces::AuthObserverInterface::FullState state,
const std::string &  authId,
const std::string &  userId 
)
overridevirtual

Reports the state change. This should be called in accordance with state transitions documented in AuthObserverInterface::State. UserId may not initially be available in the AUTHORIZING state. The values obtained in REFRESHED will be carried forward for future callbacks for validation purposes.

Parameters
stateThe state.
authIdThe unique auth id.
userIdThe user id associated with this.

Implements alexaClientSDK::acsdkAuthorizationInterfaces::AuthorizationManagerInterface.

◆ setRegistrationManager()

void alexaClientSDK::acsdkAuthorization::AuthorizationManager::setRegistrationManager ( const std::shared_ptr< registrationManager::RegistrationManagerInterface registrationManager)

Set the RegistrationManagerInterface instance.

Parameters
registrationManagerThe object used to logout.

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

AlexaClientSDK 3.0.0 - Copyright 2016-2022 Amazon.com, Inc. or its affiliates. All Rights Reserved. Licensed under the Apache License, Version 2.0