Ditto 4.13.1
 
Loading...
Searching...
No Matches
Identity.hpp
1#ifndef DITTO_IDENTITY_H
2#define DITTO_IDENTITY_H
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
57class Identity {
58 friend class Ditto;
59 friend class ManualIdentity;
60 friend class OfflinePlaygroundIdentity;
61 friend class OnlineWithAuthenticationIdentity;
62 friend class OnlinePlaygroundIdentity;
63 friend class SharedKeyIdentity;
64
65public:
66 IdentityType type;
67 virtual ~Identity();
68
76 static std::shared_ptr<OfflinePlaygroundIdentity>
77 OfflinePlayground(std::string app_id = "");
78
93 static std::shared_ptr<OfflinePlaygroundIdentity> DITTO_DEPRECATED_BECAUSE(
94 "Use the OfflinePlayground() function that does not specify a `site_id` "
95 "instead. Use `peer_key` to uniquely identify a peer")
96 OfflinePlayground(std::string app_id, uint64_t site_id);
97
109 static std::shared_ptr<OnlineWithAuthenticationIdentity>
110 OnlineWithAuthentication(std::string app_id,
111 std::shared_ptr<AuthenticationCallback> callback,
112 bool enable_ditto_cloud_sync = true,
113 std::string custom_auth_url = "");
114
128 static std::shared_ptr<OnlinePlaygroundIdentity>
129 OnlinePlayground(std::string app_id, std::string token,
130 bool enable_ditto_cloud_sync = true,
131 std::string custom_auth_url = "");
140 static std::shared_ptr<SharedKeyIdentity> SharedKey(std::string app_id,
141 std::string shared_key);
142
157 static std::shared_ptr<SharedKeyIdentity> DITTO_DEPRECATED_BECAUSE(
158 "Use the SharedKey() function that does not specify a `site_id` "
159 "instead. Use `peer_key` to uniquely identify a peer")
160 SharedKey(std::string app_id, std::string shared_key, uint64_t site_id);
161
168 static std::shared_ptr<ManualIdentity> Manual(std::string certificate_config);
169
170private:
171 virtual std::string get_app_id() const;
172 virtual bool get_enable_ditto_cloud_sync() const;
173 virtual bool requires_offline_license_token() const;
174
178 virtual CIdentityConfig_t *build_identity_config() = 0;
179};
180
186class OfflinePlaygroundIdentity : public Identity {
187 friend class Identity;
188
189public:
195 DITTO_DEPRECATED_BECAUSE("Use `peer_key` instead to uniquely identify a peer")
196 uint64_t site_id; // NOLINT
197
198private:
199 OfflinePlaygroundIdentity(std::string app_id);
200
206 DITTO_DEPRECATED_BECAUSE(
207 "Use the OfflinePlaygroundIdentity constructor that does not specify a "
208 "`site_id`. Use `peer_key` instead to uniquely identify a peer.")
209 OfflinePlaygroundIdentity(std::string app_id, uint64_t site_id);
210
211 std::string app_id;
212 std::string get_app_id() const override;
213 bool requires_offline_license_token() const override;
214 CIdentityConfig_t *build_identity_config() override;
215};
216
237class OnlineWithAuthenticationIdentity : public Identity {
238 friend class Ditto;
239 friend class Identity;
240
241public:
245 // TODO(v5): make enable_ditto_cloud_sync private and add a getter
247
252 // TODO(v5): make custom_auth_url private and add a getter
253 std::string custom_auth_url; // NOLINT
254
255private:
256 OnlineWithAuthenticationIdentity(
257 std::string app_id, std::shared_ptr<AuthenticationCallback> callback,
258 bool enable_ditto_cloud_sync, std::string custom_auth_url);
259
260 std::string app_id;
261 std::shared_ptr<AuthenticationCallback> callback;
262 std::string get_app_id() const override;
263 bool get_enable_ditto_cloud_sync() const override;
264 bool requires_offline_license_token() const override;
265 CIdentityConfig_t *build_identity_config() override;
266};
267
273class OnlinePlaygroundIdentity : public Identity {
274 friend class Identity;
275
276public:
281 // TODO(v5): make token private and add a getter
282 std::string token; // NOLINT
283
287 // TODO(v5): make enable_ditto_cloud_sync private and add a getter
289
294 // TODO(v5): make custom_auth_url private and add a getter
295 std::string custom_auth_url; // NOLINT
296
297private:
298 OnlinePlaygroundIdentity(std::string app_id, std::string token,
300 std::string custom_auth_url);
301
302 std::string app_id;
303 std::string get_app_id() const override;
304 std::string get_token() const;
305 bool get_enable_ditto_cloud_sync() const override;
306 bool requires_offline_license_token() const override;
307 CIdentityConfig_t *build_identity_config() override;
308};
309
316class SharedKeyIdentity : public Identity {
317 friend class Identity;
318
319public:
323 // TODO(v5): make shared_key private and add a getter
324 std::string shared_key; // NOLINT
325
331 DITTO_DEPRECATED_BECAUSE(
332 "Use `peer_key` instead to uniquely identify a peer.")
333 uint64_t site_id; // NOLINT
334
335private:
336 SharedKeyIdentity(std::string app_id, std::string shared_key);
337
342 DITTO_DEPRECATED_BECAUSE(
343 "Use the @ref SharedKeyIdentity constructor that does not specify a "
344 "`site_id` instead. Use `peer_key` to uniquely identify a peer.")
345 SharedKeyIdentity(std::string app_id, std::string shared_key,
346 uint64_t site_id);
347
348 std::string app_id;
349 std::string get_app_id() const override;
350 bool requires_offline_license_token() const override;
351 CIdentityConfig_t *build_identity_config() override;
352};
353
358class ManualIdentity : public Identity {
359 friend class Identity;
360
361public:
367
368private:
369 explicit ManualIdentity(std::string certificate_config);
370 bool requires_offline_license_token() const override;
371 CIdentityConfig_t *build_identity_config() override;
372};
373
374} // namespace ditto
375
376#endif
Provides feedback to the developer about Ditto authentication status.
Definition AuthenticationCallback.hpp:13
The various identity configurations that you can use when initializing a Ditto instance.
Definition Identity.hpp:57
static std::shared_ptr< ManualIdentity > Manual(std::string certificate_config)
Construct a new ManualIdentity.
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.
static std::shared_ptr< OfflinePlaygroundIdentity > OfflinePlayground(std::string app_id="")
Construct a new OfflinePlaygroundIdentity.
static std::shared_ptr< SharedKeyIdentity > SharedKey(std::string app_id, std::string shared_key)
Construct a new SharedKeyIdentity.
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.
A manually-provided certificate identity. This accepts a base64-encoded bundle.
Definition Identity.hpp:358
std::string certificate_config
Definition Identity.hpp:366
Develop peer-to-peer apps with no cloud connection. This mode offers no security and must only be use...
Definition Identity.hpp:186
uint64_t site_id
Definition Identity.hpp:196
Test a Ditto Cloud app with weak shared token authentication ("Playground mode"). This is not secure ...
Definition Identity.hpp:273
std::string custom_auth_url
Definition Identity.hpp:295
std::string token
Definition Identity.hpp:282
bool enable_ditto_cloud_sync
Definition Identity.hpp:288
Run Ditto in secure production mode, logging on to Ditto Cloud or on on-premises authentication serve...
Definition Identity.hpp:237
std::string custom_auth_url
Definition Identity.hpp:253
bool enable_ditto_cloud_sync
Definition Identity.hpp:246
A mode where any device is trusted provided they know the secret key. This is a simplistic authentica...
Definition Identity.hpp:316
std::string shared_key
Definition Identity.hpp:324
uint64_t site_id
Definition Identity.hpp:333
Namespace for the Ditto C++ SDK types and functions.
Definition AbstractDocumentPath.hpp:19
IdentityType
The different types of Identity that can be used with Ditto.
Definition Identity.hpp:21
std::string default_auth_url(std::string app_id)
Helper function to compute the default auth URL.