Ditto 1.1.7
Identity.hpp
1#ifndef _DITTO_IDENTITY_
2#define _DITTO_IDENTITY_
3
4#include "AuthenticationCallback.hpp"
5
6#include "dittoffi.hpp"
7
8#include <memory>
9#include <string>
10
11namespace ditto {
12class Authenticator;
13class LoginProvider;
14
15class DevelopmentIdentity;
16class OfflinePlaygroundIdentity;
17class OnlineIdentity;
18class OnlineWithAuthenticationIdentity;
19class OnlinePlaygroundIdentity;
20class OnlinePlaygroundV2Identity;
21class SharedKeyIdentity;
22class ManualIdentity;
23
27enum class IdentityType {
28 DEVELOPMENT,
29 OFFLINE_PLAYGROUND,
30 ONLINE,
31 ONLINE_WITH_AUTHENTICATION,
32 ONLINE_PLAYGROUND,
33 ONLINE_PLAYGROUND_V2,
34 SHARED_KEY,
35 MANUAL,
36};
37
65class Identity {
66 friend class Ditto;
67 friend class DevelopmentIdentity;
68 friend class ManualIdentity;
69 friend class OfflinePlaygroundIdentity;
70 friend class OnlineIdentity;
72 friend class OnlinePlaygroundIdentity;
73 friend class OnlinePlaygroundV2Identity;
74 friend class SharedKeyIdentity;
75 friend class Sync;
76
77public:
78 IdentityType type;
79 virtual ~Identity(){};
80
96 static std::shared_ptr<DevelopmentIdentity>
97 Development(std::string app_id = "", uint64_t site_id = 0,
98 std::string persistence_dir = "");
99
113 static std::shared_ptr<OfflinePlaygroundIdentity>
114 OfflinePlayground(std::string app_id = "", uint64_t site_id = 0,
115 std::string persistence_dir = "");
116
132 static std::shared_ptr<OnlineIdentity>
133 Online(std::string app_id, std::shared_ptr<AuthenticationCallback> callback,
134 bool enable_ditto_cloud_sync = true, std::string custom_auth_url = "",
135 std::string persistence_dir = "");
136
150 static std::shared_ptr<OnlineWithAuthenticationIdentity>
151 OnlineWithAuthentication(std::string app_id,
152 std::shared_ptr<AuthenticationCallback> callback,
153 bool enable_ditto_cloud_sync = true,
154 std::string custom_auth_url = "",
155 std::string persistence_dir = "");
156
167 static std::shared_ptr<OnlinePlaygroundIdentity>
168 OnlinePlayground(std::string app_id, bool enable_ditto_cloud_sync = true,
169 std::string persistence_dir = "");
170
187 static std::shared_ptr<OnlinePlaygroundV2Identity>
188 OnlinePlaygroundV2(std::string app_id, std::string token,
189 bool enable_ditto_cloud_sync = true,
190 std::string persistence_dir = "");
191
204 static std::shared_ptr<SharedKeyIdentity>
205 SharedKey(std::string app_id, std::string shared_key, uint64_t site_id = 0,
206 std::string persistence_dir = "");
207
214 static std::shared_ptr<ManualIdentity> Manual(std::string certificate_config);
215
216private:
217 virtual std::string get_app_id() const;
218 virtual std::shared_ptr<Authenticator> get_authenticator() const;
219 virtual bool get_enable_ditto_cloud_sync() const;
220 virtual bool requires_offline_license_token() const;
221 std::shared_ptr<CAuthClient_t> auth_client;
222};
223
232 friend class Identity;
233
234public:
238 std::string app_id;
239
243 uint64_t site_id;
244
245private:
246 DevelopmentIdentity(std::string app_id, uint64_t site_id,
247 std::string persistence_dir);
248
249 std::string get_app_id() const;
250 bool requires_offline_license_token() const;
251};
252
259 friend class Identity;
260
261public:
265 std::string app_id;
266
270 uint64_t site_id;
271
272private:
273 OfflinePlaygroundIdentity(std::string app_id, uint64_t site_id,
274 std::string persistence_dir);
275
276 std::string get_app_id() const;
277 bool requires_offline_license_token() const;
278};
279
302class OnlineIdentity : public Identity {
303 friend class Identity;
304
305public:
309 std::string app_id;
310
315
320 std::string custom_auth_url;
321
322private:
323 OnlineIdentity(std::string app_id,
324 std::shared_ptr<AuthenticationCallback> callback,
326 std::string persistence_dir);
327
328 std::string get_app_id() const;
329 bool get_enable_ditto_cloud_sync() const;
330 std::shared_ptr<Authenticator> get_authenticator();
331 std::shared_ptr<Authenticator> authenticator;
332 std::shared_ptr<LoginProvider> login_provider;
333 bool requires_offline_license_token() const;
334};
335
357 friend class Identity;
358
359public:
363 std::string app_id;
364
369
374 std::string custom_auth_url;
375
376private:
378 std::string app_id, std::shared_ptr<AuthenticationCallback> callback,
380 std::string persistence_dir);
381
382 std::string get_app_id() const;
383 bool get_enable_ditto_cloud_sync() const;
384 std::shared_ptr<Authenticator> get_authenticator() const;
385 std::shared_ptr<Authenticator> authenticator;
386 std::shared_ptr<LoginProvider> login_provider;
387 bool requires_offline_license_token() const;
388};
389
395 friend class Identity;
396
397public:
401 std::string app_id;
402
407
408private:
410 std::string persistence_dir);
411
412 std::string get_app_id() const;
413 bool get_enable_ditto_cloud_sync() const;
414 bool requires_offline_license_token() const;
415};
416
423 friend class Identity;
424
425public:
429 std::string app_id;
430
435 std::string token;
436
441
442private:
443 OnlinePlaygroundV2Identity(std::string app_id, std::string token,
445 std::string persistence_dir);
446
447 std::string get_app_id() const;
448 std::string get_token() const;
449 bool get_enable_ditto_cloud_sync() const;
450 bool requires_offline_license_token() const;
451 std::shared_ptr<Authenticator> get_authenticator() const;
452 std::shared_ptr<Authenticator> authenticator;
453};
454
462 friend class Identity;
463
464public:
468 std::string app_id;
469
473 std::string shared_key;
474
478 uint64_t site_id;
479
480private:
481 SharedKeyIdentity(std::string name, std::string shared_key, uint64_t site_id,
482 std::string persistence_dir);
483
484 std::string get_app_id() const;
485 bool requires_offline_license_token() const;
486};
487
492class ManualIdentity : public Identity {
493 friend class Identity;
494
495public:
501
502private:
503 explicit ManualIdentity(std::string certificate_config);
504 bool requires_offline_license_token() const;
505};
506
507} // namespace ditto
508
509#endif
Develop peer-to-peer apps with no cloud connection. This mode offers no security and must only be use...
Definition: Identity.hpp:231
uint64_t site_id
Definition: Identity.hpp:243
std::string app_id
Definition: Identity.hpp:238
The entrypoint to the Ditto SDK.
Definition: Ditto.hpp:22
The various identity configurations that you can use when initializing a Ditto instance.
Definition: Identity.hpp:65
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="", std::string persistence_dir="")
Construct a new OnlineWithAuthenticationIdentity.
Definition: Identity.cpp:51
static std::shared_ptr< OnlinePlaygroundV2Identity > OnlinePlaygroundV2(std::string app_id, std::string token, bool enable_ditto_cloud_sync=true, std::string persistence_dir="")
Construct a new OnlinePlaygroundV2Identity.
Definition: Identity.cpp:69
static std::shared_ptr< DevelopmentIdentity > Development(std::string app_id="", uint64_t site_id=0, std::string persistence_dir="")
Construct a new DevelopmentIdentity.
Definition: Identity.cpp:27
static std::shared_ptr< OnlinePlaygroundIdentity > OnlinePlayground(std::string app_id, bool enable_ditto_cloud_sync=true, std::string persistence_dir="")
Construct a new OnlinePlaygroundIdentity.
Definition: Identity.cpp:62
static std::shared_ptr< ManualIdentity > Manual(std::string certificate_config)
Construct a new ManualIdentity.
Definition: Identity.cpp:85
static std::shared_ptr< SharedKeyIdentity > SharedKey(std::string app_id, std::string shared_key, uint64_t site_id=0, std::string persistence_dir="")
Construct a new SharedKeyIdentity.
Definition: Identity.cpp:78
static std::shared_ptr< OnlineIdentity > Online(std::string app_id, std::shared_ptr< AuthenticationCallback > callback, bool enable_ditto_cloud_sync=true, std::string custom_auth_url="", std::string persistence_dir="")
Construct a new OnlineIdentity.
Definition: Identity.cpp:41
static std::shared_ptr< OfflinePlaygroundIdentity > OfflinePlayground(std::string app_id="", uint64_t site_id=0, std::string persistence_dir="")
Construct a new OfflinePlaygroundIdentity.
Definition: Identity.cpp:34
A manually-provided certificate identity. This accepts a base64-encoded bundle.
Definition: Identity.hpp:492
std::string certificate_config
Definition: Identity.hpp:500
Develop peer-to-peer apps with no cloud connection. This mode offers no security and must only be use...
Definition: Identity.hpp:258
std::string app_id
Definition: Identity.hpp:265
uint64_t site_id
Definition: Identity.hpp:270
Run Ditto in secure production mode, logging on to Ditto Cloud or on on-premises authentication serve...
Definition: Identity.hpp:302
std::string custom_auth_url
Definition: Identity.hpp:320
bool enable_ditto_cloud_sync
Definition: Identity.hpp:314
std::string app_id
Definition: Identity.hpp:309
Test a Ditto Cloud app without authentication ("Playground mode"). This mode offers no security and m...
Definition: Identity.hpp:394
std::string app_id
Definition: Identity.hpp:401
bool enable_ditto_cloud_sync
Definition: Identity.hpp:406
Test a Ditto Cloud app with weak shared token authentication ("Playground mode"). This is not secure ...
Definition: Identity.hpp:422
bool enable_ditto_cloud_sync
Definition: Identity.hpp:440
std::string token
Definition: Identity.hpp:435
std::string app_id
Definition: Identity.hpp:429
Run Ditto in secure production mode, logging on to Ditto Cloud or on on-premises authentication serve...
Definition: Identity.hpp:356
std::string app_id
Definition: Identity.hpp:363
std::string custom_auth_url
Definition: Identity.hpp:374
bool enable_ditto_cloud_sync
Definition: Identity.hpp:368
A mode where any device is trusted provided they know the secret key. This is a simplistic authentica...
Definition: Identity.hpp:461
std::string shared_key
Definition: Identity.hpp:473
uint64_t site_id
Definition: Identity.hpp:478
std::string app_id
Definition: Identity.hpp:468