Ditto  3.0.4
Authenticator.hpp
1 #ifndef _DITTO_AUTHENTICATOR_
2 #define _DITTO_AUTHENTICATOR_
3 
4 #include "Ditto.hpp"
5 
6 #include "AuthenticationCallback.hpp"
7 #include "AuthenticationStatus.hpp"
8 #include "Observer.hpp"
9 
10 #include "dittoffi.hpp"
11 
12 #include <functional>
13 #include <memory>
14 #include <string>
15 #include <vector>
16 
17 namespace ditto {
18 class DittoError;
19 class AuthenticationStatusObserver;
20 
26 class Authenticator : public std::enable_shared_from_this<Authenticator> {
27  friend class Ditto;
28  friend class OnlineIdentity;
30  friend class OnlinePlaygroundIdentity;
31  friend class LoginProvider;
32  friend class AuthenticationStatusObserver;
33  friend class ValidityListener;
34 
35 public:
40 
49  void login_with_token(
50  std::string token, std::string provider,
51  std::function<void(std::unique_ptr<DittoError>)> login_handler) const;
52 
65  std::string username, std::string password, std::string provider,
66  std::function<void(std::unique_ptr<DittoError>)> login_handler) const;
67 
80  void logout(std::function<void(Ditto)> cleanup = [](Ditto ditto) {}) const;
81 
87  std::shared_ptr<Observer>
88  observe_status(std::function<void(AuthenticationStatus status)> callback);
89 
90  ~Authenticator();
91 
92 private:
93  AuthenticationStatus _status;
94  std::shared_ptr<CAuthClient_t> auth_client;
95  std::weak_ptr<Ditto::Fields> weak_ditto_fields;
96  std::weak_ptr<AuthenticationCallback> callback;
97  std::vector<std::weak_ptr<AuthenticationStatusObserver>> status_observers;
98 
99  Authenticator(std::shared_ptr<CAuthClient_t> auth_client,
100  std::shared_ptr<AuthenticationCallback> callback);
101 
102  void set_weak_ditto_fields(std::weak_ptr<Ditto::Fields> weak_ditto_fields);
103  void stop_status_observer(
104  std::shared_ptr<AuthenticationStatusObserver> status_observer);
105  void validity_updated(bool web_valid, bool x509_valid);
106  void authentication_expiring(uint32_t time_remaining);
107  void update_and_notify(bool shouldNotify);
108 };
109 
110 } // namespace ditto
111 
112 #endif
Definition: AuthenticationStatusObserver.hpp:15
Provides access to authentication information and methods for logging on to Ditto Cloud....
Definition: Authenticator.hpp:26
std::shared_ptr< Observer > observe_status(std::function< void(AuthenticationStatus status)> callback)
Definition: Authenticator.cpp:76
void logout(std::function< void(Ditto)> cleanup=[](Ditto ditto) {}) const
Log out of Ditto.
Definition: Authenticator.cpp:63
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.
Definition: Authenticator.cpp:35
AuthenticationStatus get_status() const
Definition: Authenticator.cpp:33
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.
Definition: Authenticator.cpp:49
The entrypoint to the Ditto SDK.
Definition: Ditto.hpp:28
Test a Ditto Cloud app with weak shared token authentication ("Playground mode"). This is not secure ...
Definition: Identity.hpp:231
Run Ditto in secure production mode, logging on to Ditto Cloud or on on-premises authentication serve...
Definition: Identity.hpp:196
Provides info about the authentication status.
Definition: AuthenticationStatus.hpp:10