Ditto  3.0.4
Identity.hpp
1 #ifndef _DITTO_IDENTITY_
2 #define _DITTO_IDENTITY_
3 
4 #include "AuthenticationCallback.hpp"
5 #include "Helpers.hpp"
6 #include "dittoffi.hpp"
7 
8 #include <memory>
9 #include <string>
10 
11 namespace ditto {
12 class Authenticator;
13 class LoginProvider;
14 
15 class OfflinePlaygroundIdentity;
16 class OnlineWithAuthenticationIdentity;
17 class OnlinePlaygroundIdentity;
18 class SharedKeyIdentity;
19 class ManualIdentity;
20 
24 enum class IdentityType {
25  OFFLINE_PLAYGROUND,
26  ONLINE_WITH_AUTHENTICATION,
27  ONLINE_PLAYGROUND,
28  SHARED_KEY,
29  MANUAL,
30 };
31 
53 class Identity {
54  friend class Ditto;
55  friend class ManualIdentity;
56  friend class OfflinePlaygroundIdentity;
58  friend class OnlinePlaygroundIdentity;
59  friend class SharedKeyIdentity;
60  friend class Sync;
61 
62 public:
63  IdentityType type;
64  virtual ~Identity(){};
65 
77  static std::shared_ptr<OfflinePlaygroundIdentity>
78  OfflinePlayground(std::string app_id = "", uint64_t site_id = 0);
79 
91  static std::shared_ptr<OnlineWithAuthenticationIdentity>
92  OnlineWithAuthentication(std::string app_id,
93  std::shared_ptr<AuthenticationCallback> callback,
94  bool enable_ditto_cloud_sync = true,
95  std::string custom_auth_url = "");
96 
110  static std::shared_ptr<OnlinePlaygroundIdentity>
111  OnlinePlayground(std::string app_id, std::string token,
112  bool enable_ditto_cloud_sync = true);
113 
124  static std::shared_ptr<SharedKeyIdentity>
125  SharedKey(std::string app_id, std::string shared_key, uint64_t site_id = 0);
126 
133  static std::shared_ptr<ManualIdentity> Manual(std::string certificate_config);
134 
135 private:
136  virtual std::string get_app_id() const final;
137  virtual std::shared_ptr<Authenticator> get_authenticator() const;
138  virtual bool get_enable_ditto_cloud_sync() const;
139  virtual bool requires_offline_license_token() const;
140 
147  virtual std::shared_ptr<CAuthClient_t>
148  authenticate(std::string persistence_dir = "") = 0;
149 
150  void close();
151  std::shared_ptr<CAuthClient_t> auth_client;
152 };
153 
160  friend class Identity;
161 
162 public:
166  uint64_t site_id;
167 
168 private:
169  OfflinePlaygroundIdentity(std::string app_id, uint64_t site_id);
170 
171  std::string app_id;
172  std::shared_ptr<CAuthClient_t> authenticate(std::string persistence_dir = "");
173  bool requires_offline_license_token() const;
174 };
175 
197  friend class Identity;
198 
199 public:
204 
209  std::string custom_auth_url;
210 
211 private:
213  std::string app_id, std::shared_ptr<AuthenticationCallback> callback,
214  bool enable_ditto_cloud_sync, std::string custom_auth_url);
215 
216  std::string app_id;
217  bool get_enable_ditto_cloud_sync() const;
218  std::shared_ptr<Authenticator> get_authenticator() const;
219  std::shared_ptr<CAuthClient_t> authenticate(std::string persistence_dir = "");
220  std::shared_ptr<Authenticator> authenticator;
221  std::shared_ptr<LoginProvider> login_provider;
222  std::shared_ptr<AuthenticationCallback> callback;
223  bool requires_offline_license_token() const;
224 };
225 
232  friend class Identity;
233 
234 public:
239  std::string token;
240 
245 
246 private:
247  OnlinePlaygroundIdentity(std::string app_id, std::string token,
249 
250  std::string app_id;
251  std::string get_token() const;
252  bool get_enable_ditto_cloud_sync() const;
253  bool requires_offline_license_token() const;
254  std::shared_ptr<Authenticator> get_authenticator() const;
255  std::shared_ptr<CAuthClient_t> authenticate(std::string persistence_dir = "");
256  std::shared_ptr<Authenticator> authenticator;
257 };
258 
265 class SharedKeyIdentity : public Identity {
266  friend class Identity;
267 
268 public:
272  std::string shared_key;
273 
277  uint64_t site_id;
278 
279 private:
280  SharedKeyIdentity(std::string app_id, std::string shared_key,
281  uint64_t site_id);
282 
283  std::string app_id;
284  bool requires_offline_license_token() const;
285  std::shared_ptr<CAuthClient_t> authenticate(std::string persistence_dir = "");
286 };
287 
292 class ManualIdentity : public Identity {
293  friend class Identity;
294 
295 public:
300  std::string certificate_config;
301 
302 private:
303  std::shared_ptr<CAuthClient_t> authenticate(std::string persistence_dir = "");
304  explicit ManualIdentity(std::string certificate_config);
305  bool requires_offline_license_token() const;
306 };
307 
308 } // namespace ditto
309 
310 #endif
The entrypoint to the Ditto SDK.
Definition: Ditto.hpp:28
The various identity configurations that you can use when initializing a Ditto instance.
Definition: Identity.hpp:53
static std::shared_ptr< OnlinePlaygroundIdentity > OnlinePlayground(std::string app_id, std::string token, bool enable_ditto_cloud_sync=true)
Construct a new OnlinePlaygroundIdentity.
Definition: Identity.cpp:53
static std::shared_ptr< OfflinePlaygroundIdentity > OfflinePlayground(std::string app_id="", uint64_t site_id=0)
Construct a new OfflinePlaygroundIdentity.
Definition: Identity.cpp:38
static std::shared_ptr< SharedKeyIdentity > SharedKey(std::string app_id, std::string shared_key, uint64_t site_id=0)
Construct a new SharedKeyIdentity.
Definition: Identity.cpp:60
static std::shared_ptr< OnlineWithAuthenticationIdentity > OnlineWithAuthentication(std::string app_id, std::shared_ptr< AuthenticationCallback > callback, bool enable_ditto_cloud_sync=true, std::string custom_auth_url="")
Construct a new OnlineWithAuthenticationIdentity.
Definition: Identity.cpp:44
static std::shared_ptr< ManualIdentity > Manual(std::string certificate_config)
Construct a new ManualIdentity.
Definition: Identity.cpp:67
A manually-provided certificate identity. This accepts a base64-encoded bundle.
Definition: Identity.hpp:292
std::string certificate_config
Definition: Identity.hpp:300
Develop peer-to-peer apps with no cloud connection. This mode offers no security and must only be use...
Definition: Identity.hpp:159
uint64_t site_id
Definition: Identity.hpp:166
Test a Ditto Cloud app with weak shared token authentication ("Playground mode"). This is not secure ...
Definition: Identity.hpp:231
std::string token
Definition: Identity.hpp:239
bool enable_ditto_cloud_sync
Definition: Identity.hpp:244
Run Ditto in secure production mode, logging on to Ditto Cloud or on on-premises authentication serve...
Definition: Identity.hpp:196
std::string custom_auth_url
Definition: Identity.hpp:209
bool enable_ditto_cloud_sync
Definition: Identity.hpp:203
A mode where any device is trusted provided they know the secret key. This is a simplistic authentica...
Definition: Identity.hpp:265
std::string shared_key
Definition: Identity.hpp:272
uint64_t site_id
Definition: Identity.hpp:277