Ditto Basics
Authentication and Initialization
this article provides an introduction to ditto's methods for authentication, as well as step‑by‑step instructions on how to use the online playground authentication mode to initialize ditto and start prototyping for hybrid online‑offline sync /#introduction to authentication /#try on ditto online playground introduction to authentication ditto's security relies on digital identities for peer to peer authentication and access control permissions and privileges each instance of ditto running in your app must prove its identity to other peers before it is allowed to sync the following table provides an overview of authentication in ditto method use case onlineplayground ¹ you're ready to explore and test realtime sync capabilities without the commitment using either a demo app or your own development app (see /#try on ditto online playground ) onlinewithauthentication you've integrated ditto, integrated a third‑party identity service provider, and are now ready to go into production (see platform manual > docid 7zdixgnewxd7r3 k5yesa and docid\ z3l5kqjwmdu2dclki4pfb ) ¹do not use the online playground identity for production level apps the online playground is intended for testing and experimentation purposes only deploying playground certificates to a live environment could lead to vulnerabilities and security risks try on ditto online playground using ditto's online playground identity, you can sync with other peers that share the same app id and read and write to collections without the hassle of needing to set up your own authentication each instance of ditto running in your app is assigned a random universally unique identifier (uuid), which is the string of alphanumeric characters that identify your app across ditto, as well as all other systems and environments the online playground is an authentication mode that allows you to explore platform features and functionality without the hassle of setting up your own authentication mechanism before you can sync offline, you must connect to the internet to obtain your playground certificate from the big peer for more information, see /#online playground identity , as follows online playground identity before you can sync offline, you must first connect to the internet to retrieve your playground certificate unless you have a specialized use case, such as a government app, you must connect to the internet at least once before you can sync offline with other peers for more information, see docid\ gulmsvyg3oltps43d4vt the playground certificate is an x 509 formatted certificate generated automatically by the big peer when a network connection is available once you've obtained your playground certificate from the big peer, you can go offline and sync with unrestricted platform access for a maximum of one week — reading and writing to all collections and establishing connections with all peers sharing the same app id after one week, however, your playground certificate expires and you lose access to the platform, requiring you to reconnect to the internet so the big peer can automatically generate a new playground certificate initializing ditto and going offline to explore ditto without the commitment, authenticate using the playground identity for additional context, see the docid\ omdwcc1nphgiug6bwsijy for your language if you want to use ditto in an air gapped environment that is entirely offline or on‑premise, contact ditto customer engineering (see docid\ xhd0mbuhs mkv5fohdwfb ) from the portal, create an app and get your access credentials for instructions, see docid\ hk2s3ld8sj ti5snxwkq1 your access credentials consist of an app id and playground token the app id is a unique identifier that ditto uses to recognize your app the big peer uses the app id to identify your app before issuing your playground certificate peers that share the same app id will automatically form a mesh network, using any transports available on their respective devices for more information, see platform manual > docid 1xog8npyf3dfpisst1pjx the playground token is a passphrase that small peers use to authenticate your digital identity with the big peer once authenticated, the big peer issues a unique json web token (jwt) to establish and ensure persistence of connection between small peers and the big peer as long as the playground token remains active, your connection persists in the top most scope of the codebase of your app, set up and initialize ditto and configure your app to use the online playground for testing dittologger minimumloglevel = debug let ditto = ditto(identity onlineplayground( appid "replace me with your app id", token "replace me with your playground token" )) do { try ditto startsync() } catch (let err) { print(err localizeddescription) }try { val androiddependencies = defaultandroiddittodependencies(context) val identity = dittoidentity onlineplayground( androiddependencies, appid = "replace me with your app id", token = "replace me with your playground token" ) dittologger minimumloglevel = dittologlevel debug ditto = ditto(androiddependencies, identity) ditto startsync() } catch (e dittoerror) { log e("ditto error", e message!!) }import { init, ditto, logger } from "@dittolive/ditto" logger minimumloglevel = 'debug' const identity identity = { type 'onlineplayground', appid 'replace me with your app id', token 'replace me with your playground token' } const path = ' /your ditto application data path' const ditto = new ditto(identity, path) ditto startsync()import { init, ditto, logger } from "@dittolive/ditto" logger minimumloglevel = 'debug' const identity identity = { type 'onlineplayground', appid 'replace me with your app id', token 'replace me with your playground token' } const path = ' /your ditto application data path' const ditto = new ditto(identity, path) ditto startsync()dittodependencies androiddependencies = new defaultandroiddittodependencies(this context); dittologger setminimumloglevel(dittologlevel debug); dittoidentity identity = new dittoidentity onlineplayground(androiddependencies, "replace me with your app id", "your playground token here"); ditto ditto = new ditto(androiddependencies, identity); try { ditto startsync(); } catch(dittoerror e) { //handle error }try { dittologger setminimumloglevel(dittologlevel debug); var ditto = new ditto(dittoidentity onlineplayground("replace me with your app id", "replace me with your playground token", true), path); ditto startsync(); } catch (dittoexception ex) { console writeline($"ditto error {ex message}"); }auto identity = identity onlineplayground("replace me with your app id", "replace me with your playground token", true); try { ditto ditto = ditto(identity, dir); ditto set minimum log level(loglevel debug); ditto start sync(); } catch (const dittoerror \&err) { }let ditto = ditto builder() // creates a `ditto data` folder in the directory containing the executing process with root(arc new(persistentroot from current exe()?)) with identity(|ditto root| { // provided as an env var, may also be provided as hardcoded string let app id = appid from env("replace me with your app id")?; let shared token = std env var("replace me with a shared token") unwrap(); let enable cloud sync = true; let custom auth url = none; onlineplayground new( ditto root, app id, shared token, enable cloud sync, custom auth url, ) })? with minimum log level(loglevel debug) build()?; ditto start sync()?;# not supported by http api