Ditto 2.0.0-alpha1
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
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
62class Identity {
63 friend class Ditto;
64 friend class DevelopmentIdentity;
65 friend class ManualIdentity;
66 friend class OfflinePlaygroundIdentity;
67 friend class OnlineIdentity;
69 friend class OnlinePlaygroundIdentity;
70 friend class OnlinePlaygroundV2Identity;
71 friend class SharedKeyIdentity;
72 friend class Sync;
73
74public:
75 IdentityType type;
76 virtual ~Identity(){};
77
91 static std::shared_ptr<OfflinePlaygroundIdentity>
92 OfflinePlayground(std::string app_id = "", uint64_t site_id = 0,
93 std::string persistence_dir = "");
94
108 static std::shared_ptr<OnlineWithAuthenticationIdentity>
109 OnlineWithAuthentication(std::string app_id,
110 std::shared_ptr<AuthenticationCallback> callback,
111 bool enable_ditto_cloud_sync = true,
112 std::string custom_auth_url = "",
113 std::string persistence_dir = "");
114
131 static std::shared_ptr<OnlinePlaygroundIdentity>
132 OnlinePlayground(std::string app_id, std::string token,
133 bool enable_ditto_cloud_sync = true,
134 std::string persistence_dir = "");
135
153 static std::shared_ptr<OnlinePlaygroundV2Identity>
154 OnlinePlaygroundV2(std::string app_id, std::string token,
155 bool enable_ditto_cloud_sync = true,
156 std::string persistence_dir = "") DITTO_DEPRECATED;
157
170 static std::shared_ptr<SharedKeyIdentity>
171 SharedKey(std::string app_id, std::string shared_key, uint64_t site_id = 0,
172 std::string persistence_dir = "");
173
180 static std::shared_ptr<ManualIdentity> Manual(std::string certificate_config);
181
182private:
183 virtual std::string get_app_id() const;
184 virtual std::shared_ptr<Authenticator> get_authenticator() const;
185 virtual bool get_enable_ditto_cloud_sync() const;
186 virtual bool requires_offline_license_token() const;
187 std::shared_ptr<CAuthClient_t> auth_client;
188};
189
196 friend class Identity;
197
198public:
202 std::string app_id;
203
207 uint64_t site_id;
208
209private:
210 OfflinePlaygroundIdentity(std::string app_id, uint64_t site_id,
211 std::string persistence_dir);
212
213 std::string get_app_id() const;
214 bool requires_offline_license_token() const;
215};
216
238 friend class Identity;
239
240public:
244 std::string app_id;
245
250
255 std::string custom_auth_url;
256
257private:
259 std::string app_id, std::shared_ptr<AuthenticationCallback> callback,
261 std::string persistence_dir);
262
263 std::string get_app_id() const;
264 bool get_enable_ditto_cloud_sync() const;
265 std::shared_ptr<Authenticator> get_authenticator() const;
266 std::shared_ptr<Authenticator> authenticator;
267 std::shared_ptr<LoginProvider> login_provider;
268 bool requires_offline_license_token() const;
269};
270
277 friend class Identity;
278 friend class OnlinePlaygroundV2Identity;
279
280public:
284 std::string app_id;
285
290 std::string token;
291
296
297private:
298 OnlinePlaygroundIdentity(std::string app_id, std::string token,
300 std::string persistence_dir);
301
302 std::string get_app_id() const;
303 std::string get_token() const;
304 bool get_enable_ditto_cloud_sync() const;
305 bool requires_offline_license_token() const;
306 std::shared_ptr<Authenticator> get_authenticator() const;
307 std::shared_ptr<Authenticator> authenticator;
308};
309
316class DITTO_DEPRECATED OnlinePlaygroundV2Identity
317 : public OnlinePlaygroundIdentity {
318 friend class Identity;
319
320private:
321 OnlinePlaygroundV2Identity(std::string app_id, std::string token,
322 bool enable_ditto_cloud_sync,
323 std::string persistence_dir)
324 : OnlinePlaygroundIdentity(app_id, token, enable_ditto_cloud_sync,
325 persistence_dir){};
326};
327
335 friend class Identity;
336
337public:
341 std::string app_id;
342
346 std::string shared_key;
347
351 uint64_t site_id;
352
353private:
354 SharedKeyIdentity(std::string name, std::string shared_key, uint64_t site_id,
355 std::string persistence_dir);
356
357 std::string get_app_id() const;
358 bool requires_offline_license_token() const;
359};
360
365class ManualIdentity : public Identity {
366 friend class Identity;
367
368public:
374
375private:
376 explicit ManualIdentity(std::string certificate_config);
377 bool requires_offline_license_token() const;
378};
379
380} // namespace ditto
381
382#endif
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:62
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:34
static std::shared_ptr< OnlinePlaygroundV2Identity > OnlinePlaygroundV2(std::string app_id, std::string token, bool enable_ditto_cloud_sync=true, std::string persistence_dir="") DITTO_DEPRECATED
Construct a new OnlinePlaygroundIdentity.
Definition: Identity.cpp:53
static std::shared_ptr< ManualIdentity > Manual(std::string certificate_config)
Construct a new ManualIdentity.
Definition: Identity.cpp:69
static std::shared_ptr< OnlinePlaygroundIdentity > OnlinePlayground(std::string app_id, std::string token, bool enable_ditto_cloud_sync=true, std::string persistence_dir="")
Construct a new OnlinePlaygroundIdentity.
Definition: Identity.cpp:45
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:62
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:27
A manually-provided certificate identity. This accepts a base64-encoded bundle.
Definition: Identity.hpp:365
std::string certificate_config
Definition: Identity.hpp:373
Develop peer-to-peer apps with no cloud connection. This mode offers no security and must only be use...
Definition: Identity.hpp:195
std::string app_id
Definition: Identity.hpp:202
uint64_t site_id
Definition: Identity.hpp:207
Test a Ditto Cloud app with weak shared token authentication ("Playground mode"). This is not secure ...
Definition: Identity.hpp:276
std::string token
Definition: Identity.hpp:290
std::string app_id
Definition: Identity.hpp:284
bool enable_ditto_cloud_sync
Definition: Identity.hpp:295
Test a Ditto Cloud app with weak shared token authentication ("Playground mode"). This is not secure ...
Definition: Identity.hpp:317
Run Ditto in secure production mode, logging on to Ditto Cloud or on on-premises authentication serve...
Definition: Identity.hpp:237
std::string app_id
Definition: Identity.hpp:244
std::string custom_auth_url
Definition: Identity.hpp:255
bool enable_ditto_cloud_sync
Definition: Identity.hpp:249
A mode where any device is trusted provided they know the secret key. This is a simplistic authentica...
Definition: Identity.hpp:334
std::string shared_key
Definition: Identity.hpp:346
uint64_t site_id
Definition: Identity.hpp:351
std::string app_id
Definition: Identity.hpp:341