Ditto 4.11.1
 
Loading...
Searching...
No Matches
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 {
16class ManualIdentity;
17
21enum class IdentityType {
22 OFFLINE_PLAYGROUND,
23 ONLINE_WITH_AUTHENTICATION,
24 ONLINE_PLAYGROUND,
25 SHARED_KEY,
26 MANUAL,
27};
28
32std::string default_auth_url(std::string app_id);
33
55class Identity {
56 friend class Ditto;
57 friend class ManualIdentity;
58 friend class OfflinePlaygroundIdentity;
59 friend class OnlineWithAuthenticationIdentity;
60 friend class OnlinePlaygroundIdentity;
61 friend class SharedKeyIdentity;
62
63public:
64 IdentityType type;
65 virtual ~Identity();
66
78 static std::shared_ptr<OfflinePlaygroundIdentity>
79 OfflinePlayground(std::string app_id = "", uint64_t site_id = 0);
80
92 static std::shared_ptr<OnlineWithAuthenticationIdentity>
93 OnlineWithAuthentication(std::string app_id,
94 std::shared_ptr<AuthenticationCallback> callback,
95 bool enable_ditto_cloud_sync = true,
96 std::string custom_auth_url = "");
97
111 static std::shared_ptr<OnlinePlaygroundIdentity>
112 OnlinePlayground(std::string app_id, std::string token,
113 bool enable_ditto_cloud_sync = true,
114 std::string custom_auth_url = "");
115
126 static std::shared_ptr<SharedKeyIdentity>
127 SharedKey(std::string app_id, std::string shared_key, uint64_t site_id = 0);
128
135 static std::shared_ptr<ManualIdentity> Manual(std::string certificate_config);
136
137private:
138 virtual std::string get_app_id() const;
139 virtual bool get_enable_ditto_cloud_sync() const;
140 virtual bool requires_offline_license_token() const;
141
145 virtual CIdentityConfig_t *build_identity_config() = 0;
146};
147
153class OfflinePlaygroundIdentity : public Identity {
154 friend class Identity;
155
156public:
160 uint64_t site_id;
161
162private:
163 OfflinePlaygroundIdentity(std::string app_id, uint64_t site_id);
164
165 std::string app_id;
166 std::string get_app_id() const;
167 bool requires_offline_license_token() const;
168 CIdentityConfig_t *build_identity_config();
169};
170
191class OnlineWithAuthenticationIdentity : public Identity {
192 friend class Ditto;
193 friend class Identity;
194
195public:
200
205 std::string custom_auth_url;
206
207private:
208 OnlineWithAuthenticationIdentity(
209 std::string app_id, std::shared_ptr<AuthenticationCallback> callback,
210 bool enable_ditto_cloud_sync, std::string custom_auth_url);
211
212 std::string app_id;
213 std::shared_ptr<AuthenticationCallback> callback;
214 std::string get_app_id() const;
215 bool get_enable_ditto_cloud_sync() const;
216 bool requires_offline_license_token() const;
217 CIdentityConfig_t *build_identity_config();
218};
219
225class OnlinePlaygroundIdentity : public Identity {
226 friend class Identity;
227
228public:
233 std::string token;
234
239
244 std::string custom_auth_url;
245
246private:
247 OnlinePlaygroundIdentity(std::string app_id, std::string token,
249 std::string custom_auth_url);
250
251 std::string app_id;
252 std::string get_app_id() const;
253 std::string get_token() const;
254 bool get_enable_ditto_cloud_sync() const;
255 bool requires_offline_license_token() const;
256 CIdentityConfig_t *build_identity_config();
257};
258
265class SharedKeyIdentity : public Identity {
266 friend class Identity;
267
268public:
272 std::string shared_key;
273
277 uint64_t site_id;
278
279private:
280 SharedKeyIdentity(std::string app_id, std::string shared_key,
281 uint64_t site_id);
282
283 std::string app_id;
284 std::string get_app_id() const;
285 bool requires_offline_license_token() const;
286 CIdentityConfig_t *build_identity_config();
287};
288
293class ManualIdentity : public Identity {
294 friend class Identity;
295
296public:
302
303private:
304 explicit ManualIdentity(std::string certificate_config);
305 bool requires_offline_license_token() const;
306 CIdentityConfig_t *build_identity_config();
307};
308
309} // namespace ditto
310
311#endif
The various identity configurations that you can use when initializing a Ditto instance.
Definition Identity.hpp:55
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:48
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:55
static std::shared_ptr< OnlinePlaygroundIdentity > OnlinePlayground(std::string app_id, std::string token, bool enable_ditto_cloud_sync=true, std::string custom_auth_url="")
Construct a new OnlinePlaygroundIdentity.
Definition Identity.cpp:40
A manually-provided certificate identity. This accepts a base64-encoded bundle.
Definition Identity.hpp:293
std::string certificate_config
Definition Identity.hpp:301
Develop peer-to-peer apps with no cloud connection. This mode offers no security and must only be use...
Definition Identity.hpp:153
uint64_t site_id
Definition Identity.hpp:160
Test a Ditto Cloud app with weak shared token authentication ("Playground mode"). This is not secure ...
Definition Identity.hpp:225
std::string custom_auth_url
Definition Identity.hpp:244
std::string token
Definition Identity.hpp:233
bool enable_ditto_cloud_sync
Definition Identity.hpp:238
Run Ditto in secure production mode, logging on to Ditto Cloud or on on-premises authentication serve...
Definition Identity.hpp:191
std::string custom_auth_url
Definition Identity.hpp:205
bool enable_ditto_cloud_sync
Definition Identity.hpp:199
A mode where any device is trusted provided they know the secret key. This is a simplistic authentica...
Definition Identity.hpp:265
std::string shared_key
Definition Identity.hpp:272
uint64_t site_id
Definition Identity.hpp:277