Ditto 4.1.0
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 OfflinePlaygroundIdentity;
13class OnlineWithAuthenticationIdentity;
14class OnlinePlaygroundIdentity;
15class SharedKeyIdentity;
16class ManualIdentity;
17
21enum class IdentityType {
22 OFFLINE_PLAYGROUND,
23 ONLINE_WITH_AUTHENTICATION,
24 ONLINE_PLAYGROUND,
25 SHARED_KEY,
26 MANUAL,
27};
28
50class Identity {
51 friend class Ditto;
52 friend class ManualIdentity;
53 friend class OfflinePlaygroundIdentity;
55 friend class OnlinePlaygroundIdentity;
56 friend class SharedKeyIdentity;
57 friend class Sync;
58
59public:
60 IdentityType type;
61 virtual ~Identity();
62
74 static std::shared_ptr<OfflinePlaygroundIdentity>
75 OfflinePlayground(std::string app_id = "", uint64_t site_id = 0);
76
88 static std::shared_ptr<OnlineWithAuthenticationIdentity>
89 OnlineWithAuthentication(std::string app_id,
90 std::shared_ptr<AuthenticationCallback> callback,
91 bool enable_ditto_cloud_sync = true,
92 std::string custom_auth_url = "");
93
107 static std::shared_ptr<OnlinePlaygroundIdentity>
108 OnlinePlayground(std::string app_id, std::string token,
109 bool enable_ditto_cloud_sync = true);
110
121 static std::shared_ptr<SharedKeyIdentity>
122 SharedKey(std::string app_id, std::string shared_key, uint64_t site_id = 0);
123
130 static std::shared_ptr<ManualIdentity> Manual(std::string certificate_config);
131
132private:
133 virtual std::string get_app_id() const;
134 virtual bool get_enable_ditto_cloud_sync() const;
135 virtual bool requires_offline_license_token() const;
136
140 virtual CIdentityConfig_t *build_identity_config() = 0;
141};
142
149 friend class Identity;
150
151public:
155 uint64_t site_id;
156
157private:
158 OfflinePlaygroundIdentity(std::string app_id, uint64_t site_id);
159
160 std::string app_id;
161 std::string get_app_id() const;
162 bool requires_offline_license_token() const;
163 CIdentityConfig_t *build_identity_config();
164};
165
187 friend class Ditto;
188 friend class Identity;
189
190public:
195
200 std::string custom_auth_url;
201
202private:
204 std::string app_id, std::shared_ptr<AuthenticationCallback> callback,
205 bool enable_ditto_cloud_sync, std::string custom_auth_url);
206
207 std::string app_id;
208 std::shared_ptr<AuthenticationCallback> callback;
209 std::string get_app_id() const;
210 bool get_enable_ditto_cloud_sync() const;
211 bool requires_offline_license_token() const;
212 CIdentityConfig_t *build_identity_config();
213};
214
221 friend class Identity;
222
223public:
228 std::string token;
229
234
235private:
236 OnlinePlaygroundIdentity(std::string app_id, std::string token,
238
239 std::string app_id;
240 std::string get_app_id() const;
241 std::string get_token() const;
242 bool get_enable_ditto_cloud_sync() const;
243 bool requires_offline_license_token() const;
244 CIdentityConfig_t *build_identity_config();
245};
246
254 friend class Identity;
255
256public:
260 std::string shared_key;
261
265 uint64_t site_id;
266
267private:
268 SharedKeyIdentity(std::string app_id, std::string shared_key,
269 uint64_t site_id);
270
271 std::string app_id;
272 std::string get_app_id() const;
273 bool requires_offline_license_token() const;
274 CIdentityConfig_t *build_identity_config();
275};
276
281class ManualIdentity : public Identity {
282 friend class Identity;
283
284public:
290
291private:
292 explicit ManualIdentity(std::string certificate_config);
293 bool requires_offline_license_token() const;
294 CIdentityConfig_t *build_identity_config();
295};
296
297} // namespace ditto
298
299#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:50
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:40
static std::shared_ptr< OfflinePlaygroundIdentity > OfflinePlayground(std::string app_id="", uint64_t site_id=0)
Construct a new OfflinePlaygroundIdentity.
Definition: Identity.cpp:25
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:47
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:31
static std::shared_ptr< ManualIdentity > Manual(std::string certificate_config)
Construct a new ManualIdentity.
Definition: Identity.cpp:54
A manually-provided certificate identity. This accepts a base64-encoded bundle.
Definition: Identity.hpp:281
std::string certificate_config
Definition: Identity.hpp:289
Develop peer-to-peer apps with no cloud connection. This mode offers no security and must only be use...
Definition: Identity.hpp:148
uint64_t site_id
Definition: Identity.hpp:155
Test a Ditto Cloud app with weak shared token authentication ("Playground mode"). This is not secure ...
Definition: Identity.hpp:220
std::string token
Definition: Identity.hpp:228
bool enable_ditto_cloud_sync
Definition: Identity.hpp:233
Run Ditto in secure production mode, logging on to Ditto Cloud or on on-premises authentication serve...
Definition: Identity.hpp:186
std::string custom_auth_url
Definition: Identity.hpp:200
bool enable_ditto_cloud_sync
Definition: Identity.hpp:194
A mode where any device is trusted provided they know the secret key. This is a simplistic authentica...
Definition: Identity.hpp:253
std::string shared_key
Definition: Identity.hpp:260
uint64_t site_id
Definition: Identity.hpp:265