Ditto 1.1.11
|
Provides access to authentication information and methods for logging on to Ditto Cloud. Relevant when using an OnlineWithAuthentication
or an Online
identity.
More...
#include <Authenticator.hpp>
Public Member Functions | |
AuthenticationStatus | get_status () const |
void | login_with_token (std::string token, std::string provider, std::function< void(std::unique_ptr< DittoError >)> login_handler) const |
Log in to Ditto with a third-party token. More... | |
void | login_with_credentials (std::string username, std::string password, std::string provider, std::function< void(std::unique_ptr< DittoError >)> login_handler) const |
Log in to Ditto with a username and password. More... | |
void | logout (std::function< void(Ditto)> cleanup=[](Ditto ditto) {}) const |
Log out of Ditto. More... | |
std::shared_ptr< Observer > | observe_status (std::function< void(AuthenticationStatus status)> callback) |
bool | is_authenticated () const |
std::string | user_id () const |
Provides access to authentication information and methods for logging on to Ditto Cloud. Relevant when using an OnlineWithAuthentication
or an Online
identity.
AuthenticationStatus ditto::Authenticator::get_status | ( | ) | const |
Returns the current authentication status.
bool ditto::Authenticator::is_authenticated | ( | ) | const |
Query whether Ditto has a valid authentication token.
This will only be true
when using an OnlineWithAuthentication
or an Online
identity, after a successful login. If the authentication token is allowed to expire then it will return false
instead.
status.is_authenticated()
instead. void ditto::Authenticator::login_with_credentials | ( | std::string | username, |
std::string | password, | ||
std::string | provider, | ||
std::function< void(std::unique_ptr< DittoError >)> | login_handler | ||
) | const |
Log in to Ditto with a username and password.
[in] | username | the username component of the credentials used for log in. |
[in] | password | the password component of the credentials used for log in. |
[in] | provider | the name of the authentication provider. |
[in] | login_handler | a lambda that will get called when the login attempt has completed. |
void ditto::Authenticator::login_with_token | ( | std::string | token, |
std::string | provider, | ||
std::function< void(std::unique_ptr< DittoError >)> | login_handler | ||
) | const |
This will stop sync, shut down all replication sessions, and remove any cached authentication credentials. Note that this does not remove any data from the store. If you wish to delete data from the store then use the optional cleanupAction
argument to perform any required cleanup.
[in] | cleanup | An optional lambda that will be called with the relevant `Ditto instance as the sole argument that allows you to perform any required cleanup of the store as part of the logout process. |
std::shared_ptr< Observer > ditto::Authenticator::observe_status | ( | std::function< void(AuthenticationStatus status)> | callback | ) |
Registers a function that will be called whenever authentication status
changes. Returns an Observer
that needs to be retained as long as you want to receive the updates.
std::string ditto::Authenticator::user_id | ( | ) | const |
Return the currently logged-in user ID.
This will return the empty string if there is no valid authentication or OnlineWithAuthentication
/Online
mode is not being used.
status.user_id()
instead.