Ditto 4.14.4
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
58class DITTO_DEPRECATED_BECAUSE("Identity types are removed in SDK 5.0. "
59 "Use DittoConfig with Ditto::open(config) "
60 "instead. See https://docs.ditto.live for "
61 "migration guide.") Identity {
62 friend class Ditto;
63 friend class ManualIdentity;
64 friend class OfflinePlaygroundIdentity;
65 friend class OnlineWithAuthenticationIdentity;
66 friend class OnlinePlaygroundIdentity;
67 friend class SharedKeyIdentity;
68
69public:
70 IdentityType type;
71 virtual ~Identity();
72
83 static std::shared_ptr<OfflinePlaygroundIdentity> DITTO_DEPRECATED_BECAUSE(
84 "Use DittoConfig with Ditto::open(config) instead. "
85 "Identity types will be removed in SDK 5.0. "
86 "See https://docs.ditto.live for migration guide.")
87 OfflinePlayground(std::string app_id = "");
88
103 static std::shared_ptr<OfflinePlaygroundIdentity> DITTO_DEPRECATED_BECAUSE(
104 "Use the OfflinePlayground() function that does not specify a `site_id` "
105 "instead. Use `peer_key` to uniquely identify a peer")
106 OfflinePlayground(std::string app_id, uint64_t site_id);
107
122 static std::shared_ptr<OnlineWithAuthenticationIdentity>
123 DITTO_DEPRECATED_BECAUSE(
124 "Use DittoConfig with Ditto::open(config) instead. "
125 "Identity types will be removed in SDK 5.0. "
126 "See https://docs.ditto.live for migration guide.")
128 std::string app_id,
129 std::shared_ptr<AuthenticationCallback> callback,
130 bool enable_ditto_cloud_sync = true,
131 std::string custom_auth_url = "");
132
149 static std::shared_ptr<OnlinePlaygroundIdentity> DITTO_DEPRECATED_BECAUSE(
150 "Use DittoConfig with Ditto::open(config) instead. "
151 "Identity types will be removed in SDK 5.0. "
152 "See https://docs.ditto.live for migration guide.")
153 OnlinePlayground(std::string app_id, std::string token,
154 bool enable_ditto_cloud_sync = true,
155 std::string custom_auth_url = "");
167 static std::shared_ptr<SharedKeyIdentity> DITTO_DEPRECATED_BECAUSE(
168 "Use DittoConfig with Ditto::open(config) instead. "
169 "Identity types will be removed in SDK 5.0. "
170 "See https://docs.ditto.live for migration guide.")
171 SharedKey(std::string app_id, std::string shared_key);
172
187 static std::shared_ptr<SharedKeyIdentity> DITTO_DEPRECATED_BECAUSE(
188 "Use the SharedKey() function that does not specify a `site_id` "
189 "instead. Use `peer_key` to uniquely identify a peer")
190 SharedKey(std::string app_id, std::string shared_key, uint64_t site_id);
191
201 static std::shared_ptr<ManualIdentity> DITTO_DEPRECATED_BECAUSE(
202 "Use DittoConfig with Ditto::open(config) instead. "
203 "Identity types will be removed in SDK 5.0. "
204 "See https://docs.ditto.live for migration guide.")
205 Manual(std::string certificate_config);
206
207private:
208 virtual std::string get_app_id() const;
209 virtual bool get_enable_ditto_cloud_sync() const;
210 virtual bool requires_offline_license_token() const;
211
215 virtual CIdentityConfig_t *build_identity_config() = 0;
216};
217
223class OfflinePlaygroundIdentity : public Identity {
224 friend class Identity;
225
226public:
232 DITTO_DEPRECATED_BECAUSE("Use `peer_key` instead to uniquely identify a peer")
233 uint64_t site_id; // NOLINT
234
235private:
236 OfflinePlaygroundIdentity(std::string app_id);
237
243 DITTO_DEPRECATED_BECAUSE(
244 "Use the OfflinePlaygroundIdentity constructor that does not specify a "
245 "`site_id`. Use `peer_key` instead to uniquely identify a peer.")
246 OfflinePlaygroundIdentity(std::string app_id, uint64_t site_id);
247
248 std::string app_id;
249 std::string get_app_id() const override;
250 bool requires_offline_license_token() const override;
251 CIdentityConfig_t *build_identity_config() override;
252};
253
274class OnlineWithAuthenticationIdentity : public Identity {
275 friend class Ditto;
276 friend class Identity;
277
278public:
282 // TODO(v5): make enable_ditto_cloud_sync private and add a getter
284
289 // TODO(v5): make custom_auth_url private and add a getter
290 std::string custom_auth_url; // NOLINT
291
292private:
293 OnlineWithAuthenticationIdentity(
294 std::string app_id, std::shared_ptr<AuthenticationCallback> callback,
295 bool enable_ditto_cloud_sync, std::string custom_auth_url);
296
297 std::string app_id;
298 std::shared_ptr<AuthenticationCallback> callback;
299 std::string get_app_id() const override;
300 bool get_enable_ditto_cloud_sync() const override;
301 bool requires_offline_license_token() const override;
302 CIdentityConfig_t *build_identity_config() override;
303};
304
310class OnlinePlaygroundIdentity : public Identity {
311 friend class Identity;
312
313public:
318 // TODO(v5): make token private and add a getter
319 std::string token; // NOLINT
320
324 // TODO(v5): make enable_ditto_cloud_sync private and add a getter
326
331 // TODO(v5): make custom_auth_url private and add a getter
332 std::string custom_auth_url; // NOLINT
333
334private:
335 OnlinePlaygroundIdentity(std::string app_id, std::string token,
337 std::string custom_auth_url);
338
339 std::string app_id;
340 std::string get_app_id() const override;
341 std::string get_token() const;
342 bool get_enable_ditto_cloud_sync() const override;
343 bool requires_offline_license_token() const override;
344 CIdentityConfig_t *build_identity_config() override;
345};
346
353class SharedKeyIdentity : public Identity {
354 friend class Identity;
355
356public:
360 // TODO(v5): make shared_key private and add a getter
361 std::string shared_key; // NOLINT
362
368 DITTO_DEPRECATED_BECAUSE(
369 "Use `peer_key` instead to uniquely identify a peer.")
370 uint64_t site_id; // NOLINT
371
372private:
373 SharedKeyIdentity(std::string app_id, std::string shared_key);
374
379 DITTO_DEPRECATED_BECAUSE(
380 "Use the @ref SharedKeyIdentity constructor that does not specify a "
381 "`site_id` instead. Use `peer_key` to uniquely identify a peer.")
382 SharedKeyIdentity(std::string app_id, std::string shared_key,
383 uint64_t site_id);
384
385 std::string app_id;
386 std::string get_app_id() const override;
387 bool requires_offline_license_token() const override;
388 CIdentityConfig_t *build_identity_config() override;
389};
390
395class ManualIdentity : public Identity {
396 friend class Identity;
397
398public:
404
405private:
406 explicit ManualIdentity(std::string certificate_config);
407 bool requires_offline_license_token() const override;
408 CIdentityConfig_t *build_identity_config() override;
409};
410
411} // namespace ditto
412
413#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:61
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:395
std::string certificate_config
Definition Identity.hpp:403
Develop peer-to-peer apps with no cloud connection. This mode offers no security and must only be use...
Definition Identity.hpp:223
uint64_t site_id
Definition Identity.hpp:233
Test a Ditto Cloud app with weak shared token authentication ("Playground mode"). This is not secure ...
Definition Identity.hpp:310
std::string custom_auth_url
Definition Identity.hpp:332
std::string token
Definition Identity.hpp:319
bool enable_ditto_cloud_sync
Definition Identity.hpp:325
Run Ditto in secure production mode, logging on to Ditto Cloud or on on-premises authentication serve...
Definition Identity.hpp:274
std::string custom_auth_url
Definition Identity.hpp:290
bool enable_ditto_cloud_sync
Definition Identity.hpp:283
A mode where any device is trusted provided they know the secret key. This is a simplistic authentica...
Definition Identity.hpp:353
std::string shared_key
Definition Identity.hpp:361
uint64_t site_id
Definition Identity.hpp:370
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.