Developer API: cloud saves

Let players sign in to your game or app with their Synkrown Hub account and keep their saves in the cloud. It works for builds hosted here and for games and apps on your own website.

1. Turn it on

  1. Open your page in My pages and go to the Cloud saves tab.
  2. Tick Turn on cloud saves and note your App ID.
  3. Optional: tick Only for owners of the full version. Players who have not bought it are then refused.
  4. Only if your game runs on another website: add the address players come back to after signing in, for example https://mygame.com/play. For testing, http://localhost:8080/ works too.

2. Add the script

<script src="https://synkrown.org/js/synkrown.js"></script>

Use this full address for builds hosted here too.

3. Sign players in

const hub = SynKrown.init({ app: 123 }); // your App ID

await hub.ready;
if (hub.user) {
  console.log('Signed in as', hub.user.display_name);
} else if (hub.error === 'no_access') {
  // They need the full version.
} else {
  signInButton.onclick = () => hub.signIn();
}

4. Save and load

await hub.saves.put('slot1', { level: 3, coins: 120 });

const save = await hub.saves.get('slot1'); // null when empty
console.log(save.data.level, save.version);

// Projects and other files: pass a Blob, File, ArrayBuffer or typed array.
await hub.saves.put('project', projectBlob);
const project = await hub.saves.get('project'); // project.data is a Blob

const list = await hub.saves.list(); // [{ slot, content_type, bytes, version, updated_at }]
await hub.saves.remove('slot1');
hub.signOut();

5. KrownOS desktop (optional)

Every member has a desktop at KrownOS. Your game or app can put things there, so players see their work and saves next to everything else.

// Show a save as an icon on their desktop. Opening it opens your game.
await hub.saves.put('slot1', data, { desktop: 'My castle' });

// Save a file to their desktop, or to a folder there named after it.
const file = await hub.desktop.save('Song.json', song, { folder: 'My songs' });

const files = await hub.desktop.list(); // only the files your app made
const loaded = await hub.desktop.load(file.id); // { data, version }
await hub.desktop.update(file.id, newSong, { version: loaded.version });
await hub.desktop.remove(file.id);

// Opened from an icon on the desktop?
if (hub.launch && hub.launch.file) openSong(await hub.desktop.load(hub.launch.file));
if (hub.launch && hub.launch.save) loadSlot(hub.launch.save);

Your data stays yours

Saves are stored per app and per player. The app is taken from the player's sign in, never from the request, so another developer using the same slot names, or even your App ID, can never read or overwrite your players' saves. Players can disconnect an app, and delete its saves, from My account.

Errors

Failed calls throw an error with a code:

HTTP API

For engines without JavaScript. Send Authorization: Bearer TOKEN with every call. Replies are JSON, apart from reading a save.

Getting a token is standard OAuth with PKCE (S256):

  1. Send the player to https://synkrown.org/api/connect?app=ID&redirect_uri=URL&state=RANDOM&code_challenge=CHALLENGE.
  2. They come back to URL?code=...&state=..., or ?error=....
  3. Within 5 minutes, POST /api/v1/token with JSON { "code", "code_verifier", "redirect_uri" }. The reply is { "token", "expires_at" }.