1#ifndef DITTO_AUTHENTICATOR_H
2#define DITTO_AUTHENTICATOR_H
6#include "AuthenticationCallback.hpp"
7#include "AuthenticationStatus.hpp"
9#include "SynchronizedValue.hpp"
11#include "authentication_status_handler.hpp"
12#include "dittoffi.hpp"
23class DittoHandleWrapper;
26using AuthenticationExpirationHandler =
27 std::function<void(
Ditto &ditto, uint32_t sec_remaining)>;
34class Authenticator :
public std::enable_shared_from_this<Authenticator> {
35 friend class AuthenticationStatusHandler;
36 friend class AuthenticationStatusObserver;
38 friend class LoginProvider;
39 friend class OnlinePlaygroundIdentity;
40 friend class OnlineWithAuthenticationIdentity;
64 void login(std::string token, std::string provider,
65 std::function<
void(std::unique_ptr<std::string>,
66 std::unique_ptr<DittoError>)>
79 DITTO_DEPRECATED_BECAUSE(
"Use `login` instead.")
81 std::
string token, std::
string provider,
82 std::function<
void(std::unique_ptr<
DittoError>)> login_handler) const;
96 std::
string username, std::
string password, std::
string provider,
97 std::function<
void(std::unique_ptr<
DittoError>)> login_handler) const;
111 void logout(std::function<
void(Ditto)> cleanup = [](Ditto
ditto) {})
const;
118 std::shared_ptr<Observer>
121 ~Authenticator() =
default;
145 std::shared_ptr<DittoHandleWrapper> ditto_handle_wrapper;
146 std::weak_ptr<Ditto::Fields> weak_ditto_fields;
148 std::vector<std::weak_ptr<AuthenticationStatusObserver>> status_observers;
149 internal::SynchronizedValue<AuthenticationExpirationHandler>
152 Authenticator(std::shared_ptr<DittoHandleWrapper> ditto_handle_wrapper,
153 std::weak_ptr<Ditto::Fields> ditto_fields,
156 void stop_status_observer(
157 std::shared_ptr<AuthenticationStatusObserver> status_observer);
158 void authentication_expiring(uint32_t time_remaining);
159 void update_and_notify(
bool should_notify);
Provides feedback to the developer about Ditto authentication status.
Definition AuthenticationCallback.hpp:13
Definition AuthenticationStatusObserver.hpp:15
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.
AuthenticationExpirationHandler get_expiration_handler() const noexcept
Get the authentication expiration callback.
static std::string get_development_provider()
Get the built-in development authentication provider to be used with development authentication token...
std::shared_ptr< Observer > observe_status(std::function< void(AuthenticationStatus status)> callback)
void logout(std::function< void(Ditto)> cleanup=[](Ditto ditto) {}) const
Log out of Ditto.
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.
AuthenticationStatus get_status() const
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 set_expiration_handler(AuthenticationExpirationHandler handler) noexcept
Set authentication expiration handler, typically provided via Identity but can be set directly.
All errors that are thrown by the Ditto SDK are wrapped as a DittoError.
Definition Errors.hpp:42
The entrypoint to the Ditto SDK.
Definition Ditto.hpp:39
Namespace for internal Ditto SDK functionality.
Definition Ditto.hpp:29
Namespace for the Ditto C++ SDK types and functions.
Definition AbstractDocumentPath.hpp:19
Provides info about the authentication status.
Definition AuthenticationStatus.hpp:10
Configuration options for initializing a Ditto instance.
Definition DittoConfig.hpp:30