Ditto 4.11.1
 
Loading...
Searching...
No Matches
ditto::Authenticator Class Reference

Provides access to authentication information and methods for logging on to Ditto Cloud. Relevant when using an OnlineWithAuthentication or an Online identity. More...

Inheritance diagram for ditto::Authenticator:

Public Member Functions

AuthenticationStatus get_status () const
 
void login (std::string token, std::string provider, std::function< void(std::unique_ptr< std::string >, std::unique_ptr< DittoError >)> login_handler) const
 Log in to Ditto with a third-party token.
 
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.
 
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.
 
void logout (std::function< void(Ditto)> cleanup=[](Ditto ditto) {}) const
 Log out of Ditto.
 
std::shared_ptr< Observerobserve_status (std::function< void(AuthenticationStatus status)> callback)
 

Detailed Description

Provides access to authentication information and methods for logging on to Ditto Cloud. Relevant when using an OnlineWithAuthentication or an Online identity.

Member Function Documentation

◆ get_status()

AuthenticationStatus ditto::Authenticator::get_status ( ) const

Returns the current authentication status.

◆ login()

void ditto::Authenticator::login ( std::string token,
std::string provider,
std::function< void(std::unique_ptr< std::string >, std::unique_ptr< DittoError >)> login_handler ) const

Log in to Ditto with a third-party token.

The completion lambda will be called once, whether the login attempt succeeds or fails. If it has failed then the optional DittoError will be non-null, otherwise it will be null. Regardless of whether or not the login attempt succeeds the optional std::string argument will be non-null if the auth webhook endpoint returned any JSON value under the clientInfo key. That JSON is what will be passed via the std::string argument, if it's provided.

Parameters
[in]tokenthe authentication token required to log in.
[in]providerthe name of the authentication provider.
[in]login_handlera lambda that will get called when the login attempt has completed.

◆ login_with_credentials()

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.

Parameters
[in]usernamethe username component of the credentials used for log in.
[in]passwordthe password component of the credentials used for log in.
[in]providerthe name of the authentication provider.
[in]login_handlera lambda that will get called when the login attempt has completed.

◆ login_with_token()

void ditto::Authenticator::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.

Deprecated
Use login() instead.
Parameters
[in]tokenthe authentication token required to log in.
[in]providerthe name of the authentication provider.
[in]login_handlera lambda that will get called when the login attempt has completed.

◆ logout()

void ditto::Authenticator::logout ( std::function< void(Ditto)> cleanup = [](Ditto ditto) {}) const

Log out of Ditto.

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.

Parameters
[in]cleanupAn 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.

◆ observe_status()

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.