Ditto 1.1.3
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 OfflinePlaygroundIdentity;
69 friend class OnlineIdentity;
71 friend class OnlinePlaygroundIdentity;
72 friend class OnlinePlaygroundV2Identity;
73 friend class SharedKeyIdentity;
74 friend class ManualIdentity;
75
76public:
77 IdentityType type;
78 virtual ~Identity(){};
79
95 static std::shared_ptr<DevelopmentIdentity>
96 Development(std::string app_id = "", uint64_t site_id = 0,
97 std::string persistence_dir = "");
98
112 static std::shared_ptr<OfflinePlaygroundIdentity>
113 OfflinePlayground(std::string app_id = "", uint64_t site_id = 0,
114 std::string persistence_dir = "");
115
131 static std::shared_ptr<OnlineIdentity>
132 Online(std::string app_id, std::shared_ptr<AuthenticationCallback> callback,
133 bool enable_ditto_cloud_sync = true, std::string custom_auth_url = "",
134 std::string persistence_dir = "");
135
149 static std::shared_ptr<OnlineWithAuthenticationIdentity>
150 OnlineWithAuthentication(std::string app_id,
151 std::shared_ptr<AuthenticationCallback> callback,
152 bool enable_ditto_cloud_sync = true,
153 std::string custom_auth_url = "",
154 std::string persistence_dir = "");
155
166 static std::shared_ptr<OnlinePlaygroundIdentity>
167 OnlinePlayground(std::string app_id, bool enable_ditto_cloud_sync = true,
168 std::string persistence_dir = "");
169
186 static std::shared_ptr<OnlinePlaygroundV2Identity>
187 OnlinePlaygroundV2(std::string app_id, std::string token,
188 bool enable_ditto_cloud_sync = true,
189 std::string persistence_dir = "");
190
203 static std::shared_ptr<SharedKeyIdentity>
204 SharedKey(std::string app_id, std::string shared_key, uint64_t site_id = 0,
205 std::string persistence_dir = "");
206
213 static std::shared_ptr<ManualIdentity> Manual(std::string certificate_config);
214
215private:
216 virtual std::string get_app_id() const;
217 virtual std::shared_ptr<Authenticator> get_authenticator() const;
218 virtual bool get_enable_ditto_cloud_sync() const;
219 virtual bool requires_offline_license_token() const;
220 std::shared_ptr<CAuthClient_t> auth_client;
221};
222
231 friend class Identity;
232
233public:
237 std::string app_id;
238
242 uint64_t site_id;
243
244private:
245 DevelopmentIdentity(std::string app_id, uint64_t site_id,
246 std::string persistence_dir);
247
248 std::string get_app_id() const;
249 bool requires_offline_license_token() const;
250};
251
258 friend class Identity;
259
260public:
264 std::string app_id;
265
269 uint64_t site_id;
270
271private:
272 OfflinePlaygroundIdentity(std::string app_id, uint64_t site_id,
273 std::string persistence_dir);
274
275 std::string get_app_id() const;
276 bool requires_offline_license_token() const;
277};
278
301class OnlineIdentity : public Identity {
302 friend class Identity;
303
304public:
308 std::string app_id;
309
314
319 std::string custom_auth_url;
320
321private:
322 OnlineIdentity(std::string app_id,
323 std::shared_ptr<AuthenticationCallback> callback,
325 std::string persistence_dir);
326
327 std::string get_app_id() const;
328 bool get_enable_ditto_cloud_sync() const;
329 std::shared_ptr<Authenticator> get_authenticator();
330 std::shared_ptr<Authenticator> authenticator;
331 std::shared_ptr<LoginProvider> login_provider;
332 bool requires_offline_license_token() const;
333};
334
356 friend class Identity;
357
358public:
362 std::string app_id;
363
368
373 std::string custom_auth_url;
374
375private:
377 std::string app_id, std::shared_ptr<AuthenticationCallback> callback,
379 std::string persistence_dir);
380
381 std::string get_app_id() const;
382 bool get_enable_ditto_cloud_sync() const;
383 std::shared_ptr<Authenticator> get_authenticator() const;
384 std::shared_ptr<Authenticator> authenticator;
385 std::shared_ptr<LoginProvider> login_provider;
386 bool requires_offline_license_token() const;
387};
388
394 friend class Identity;
395
396public:
400 std::string app_id;
401
406
407private:
409 std::string persistence_dir);
410
411 std::string get_app_id() const;
412 bool get_enable_ditto_cloud_sync() const;
413 bool requires_offline_license_token() const;
414};
415
422 friend class Identity;
423
424public:
428 std::string app_id;
429
434 std::string token;
435
440
441private:
442 OnlinePlaygroundV2Identity(std::string app_id, std::string token,
444 std::string persistence_dir);
445
446 std::string get_app_id() const;
447 std::string get_token() const;
448 bool get_enable_ditto_cloud_sync() const;
449 bool requires_offline_license_token() const;
450 std::shared_ptr<Authenticator> get_authenticator() const;
451 std::shared_ptr<Authenticator> authenticator;
452};
453
461 friend class Identity;
462
463public:
467 std::string app_id;
468
472 std::string shared_key;
473
477 uint64_t site_id;
478
479private:
480 SharedKeyIdentity(std::string name, std::string shared_key, uint64_t site_id,
481 std::string persistence_dir);
482
483 std::string get_app_id() const;
484 bool requires_offline_license_token() const;
485};
486
491class ManualIdentity : public Identity {
492 friend class Identity;
493
494public:
500
501private:
502 explicit ManualIdentity(std::string certificate_config);
503 bool requires_offline_license_token() const;
504};
505
506} // namespace ditto
507
508#endif
Develop peer-to-peer apps with no cloud connection. This mode offers no security and must only be use...
Definition: Identity.hpp:230
uint64_t site_id
Definition: Identity.hpp:242
std::string app_id
Definition: Identity.hpp:237
The entrypoint to the Ditto SDK.
Definition: Ditto.hpp:25
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:53
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:71
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:29
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:64
static std::shared_ptr< ManualIdentity > Manual(std::string certificate_config)
Construct a new ManualIdentity.
Definition: Identity.cpp:87
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:80
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:43
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:36
A manually-provided certificate identity. This accepts a base64-encoded bundle.
Definition: Identity.hpp:491
std::string certificate_config
Definition: Identity.hpp:499
Develop peer-to-peer apps with no cloud connection. This mode offers no security and must only be use...
Definition: Identity.hpp:257
std::string app_id
Definition: Identity.hpp:264
uint64_t site_id
Definition: Identity.hpp:269
Run Ditto in secure production mode, logging on to Ditto Cloud or on on-premises authentication serve...
Definition: Identity.hpp:301
std::string custom_auth_url
Definition: Identity.hpp:319
bool enable_ditto_cloud_sync
Definition: Identity.hpp:313
std::string app_id
Definition: Identity.hpp:308
Test a Ditto Cloud app without authentication ("Playground mode"). This mode offers no security and m...
Definition: Identity.hpp:393
std::string app_id
Definition: Identity.hpp:400
bool enable_ditto_cloud_sync
Definition: Identity.hpp:405
Test a Ditto Cloud app with weak shared token authentication ("Playground mode"). This is not secure ...
Definition: Identity.hpp:421
bool enable_ditto_cloud_sync
Definition: Identity.hpp:439
std::string token
Definition: Identity.hpp:434
std::string app_id
Definition: Identity.hpp:428
Run Ditto in secure production mode, logging on to Ditto Cloud or on on-premises authentication serve...
Definition: Identity.hpp:355
std::string app_id
Definition: Identity.hpp:362
std::string custom_auth_url
Definition: Identity.hpp:373
bool enable_ditto_cloud_sync
Definition: Identity.hpp:367
A mode where any device is trusted provided they know the secret key. This is a simplistic authentica...
Definition: Identity.hpp:460
std::string shared_key
Definition: Identity.hpp:472
uint64_t site_id
Definition: Identity.hpp:477
std::string app_id
Definition: Identity.hpp:467