Ditto 2.0.6
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 OfflinePlaygroundIdentity;
16class OnlineWithAuthenticationIdentity;
17class OnlinePlaygroundIdentity;
18class SharedKeyIdentity;
19class ManualIdentity;
20
24enum class IdentityType {
25 OFFLINE_PLAYGROUND,
26 ONLINE_WITH_AUTHENTICATION,
27 ONLINE_PLAYGROUND,
28 SHARED_KEY,
29 MANUAL,
30};
31
53class 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
62public:
63 IdentityType type;
64 virtual ~Identity(){};
65
79 static std::shared_ptr<OfflinePlaygroundIdentity>
80 OfflinePlayground(std::string app_id = "", uint64_t site_id = 0,
81 std::string persistence_dir = "");
82
96 static std::shared_ptr<OnlineWithAuthenticationIdentity>
97 OnlineWithAuthentication(std::string app_id,
98 std::shared_ptr<AuthenticationCallback> callback,
99 bool enable_ditto_cloud_sync = true,
100 std::string custom_auth_url = "",
101 std::string persistence_dir = "");
102
119 static std::shared_ptr<OnlinePlaygroundIdentity>
120 OnlinePlayground(std::string app_id, std::string token,
121 bool enable_ditto_cloud_sync = true,
122 std::string persistence_dir = "");
123
136 static std::shared_ptr<SharedKeyIdentity>
137 SharedKey(std::string app_id, std::string shared_key, uint64_t site_id = 0,
138 std::string persistence_dir = "");
139
146 static std::shared_ptr<ManualIdentity> Manual(std::string certificate_config);
147
148private:
149 virtual std::string get_app_id() const;
150 virtual std::shared_ptr<Authenticator> get_authenticator() const;
151 virtual bool get_enable_ditto_cloud_sync() const;
152 virtual bool requires_offline_license_token() const;
153 std::shared_ptr<CAuthClient_t> auth_client;
154};
155
162 friend class Identity;
163
164public:
168 std::string app_id;
169
173 uint64_t site_id;
174
175private:
176 OfflinePlaygroundIdentity(std::string app_id, uint64_t site_id,
177 std::string persistence_dir);
178
179 std::string get_app_id() const;
180 bool requires_offline_license_token() const;
181};
182
204 friend class Identity;
205
206public:
210 std::string app_id;
211
216
221 std::string custom_auth_url;
222
223private:
225 std::string app_id, std::shared_ptr<AuthenticationCallback> callback,
227 std::string persistence_dir);
228
229 std::string get_app_id() const;
230 bool get_enable_ditto_cloud_sync() const;
231 std::shared_ptr<Authenticator> get_authenticator() const;
232 std::shared_ptr<Authenticator> authenticator;
233 std::shared_ptr<LoginProvider> login_provider;
234 bool requires_offline_license_token() const;
235};
236
243 friend class Identity;
244
245public:
249 std::string app_id;
250
255 std::string token;
256
261
262private:
263 OnlinePlaygroundIdentity(std::string app_id, std::string token,
265 std::string persistence_dir);
266
267 std::string get_app_id() const;
268 std::string get_token() const;
269 bool get_enable_ditto_cloud_sync() const;
270 bool requires_offline_license_token() const;
271 std::shared_ptr<Authenticator> get_authenticator() const;
272 std::shared_ptr<Authenticator> authenticator;
273};
274
282 friend class Identity;
283
284public:
288 std::string app_id;
289
293 std::string shared_key;
294
298 uint64_t site_id;
299
300private:
301 SharedKeyIdentity(std::string name, std::string shared_key, uint64_t site_id,
302 std::string persistence_dir);
303
304 std::string get_app_id() const;
305 bool requires_offline_license_token() const;
306};
307
312class ManualIdentity : public Identity {
313 friend class Identity;
314
315public:
321
322private:
323 explicit ManualIdentity(std::string certificate_config);
324 bool requires_offline_license_token() const;
325};
326
327} // namespace ditto
328
329#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:53
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< ManualIdentity > Manual(std::string certificate_config)
Construct a new ManualIdentity.
Definition: Identity.cpp:60
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:53
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:312
std::string certificate_config
Definition: Identity.hpp:320
Develop peer-to-peer apps with no cloud connection. This mode offers no security and must only be use...
Definition: Identity.hpp:161
std::string app_id
Definition: Identity.hpp:168
uint64_t site_id
Definition: Identity.hpp:173
Test a Ditto Cloud app with weak shared token authentication ("Playground mode"). This is not secure ...
Definition: Identity.hpp:242
std::string token
Definition: Identity.hpp:255
std::string app_id
Definition: Identity.hpp:249
bool enable_ditto_cloud_sync
Definition: Identity.hpp:260
Run Ditto in secure production mode, logging on to Ditto Cloud or on on-premises authentication serve...
Definition: Identity.hpp:203
std::string app_id
Definition: Identity.hpp:210
std::string custom_auth_url
Definition: Identity.hpp:221
bool enable_ditto_cloud_sync
Definition: Identity.hpp:215
A mode where any device is trusted provided they know the secret key. This is a simplistic authentica...
Definition: Identity.hpp:281
std::string shared_key
Definition: Identity.hpp:293
uint64_t site_id
Definition: Identity.hpp:298
std::string app_id
Definition: Identity.hpp:288