Skip to content

Build panels

Sign in with Deska

Let people sign in to your panel’s server with their Deska account: what to declare, the two calls, checking the token on your server, development tokens, the events Deska sends when someone stops, and what you owe the people who sign in.

How it works

A panel with a server of its own (a shared board, a synced list) can sign people in with the Deska account they already use, the way a website signs people in with another account. The panel never draws a sign-in form:

  1. The person presses a button in your panel, and the page calls deska.account.signIn().
  2. Deska shows its own sheet, outside your panel: Sign in to <panel> with Deska, a link to your privacy policy, and what you receive. The person presses Continue.
  3. The page receives a token that deska.dev signed. It sends it to your server.
  4. Your server checks the token, then finds or creates the person’s account by its sub.

You always receive an id that is the person’s for your panel only: two panels never get the same id for one person, so they can never match their people. You receive their name, email, username and profile photo only when you ask for them and the person ticks them; every box starts unticked.

Heads upNever draw a password form or a sign-in page inside a panel, for Deska or for any other service. No browser feature stops a page drawing one, so Deska’s review declines a version that does. Sign people in with Deska instead.

What to declare

panel.jsonjson
{
  "permissions": ["account"],
  "network": ["api.nook.app"],
  "account": {
    "privacy": "https://nook.app/privacy",
    "events": "https://api.nook.app/deska/events"
  },
  "sdk": 4
}
  • The permission account and an account object, each needing the other.
  • privacy, required: the https address of your privacy policy. The sheet links to it.
  • events, optional: an https address where deska.dev tells your server about people who stopped. It must be on one of your network hosts. See When someone stops.
  • At least one host under network: your server, where the page sends the token.
  • "sdk": 4. An older Deska says the panel needs a newer Deska.
  • Each address is https on a host name, with no port, user name or password, and at most 2,048 characters.
  • A panel that signs people in cannot also work with a task’s agent (agent). See Panel actions.

account is asked the first time the panel uses it, never at install: the install question lists it under Asks first. A version that declares it is always reviewed before it is published. deska.dev signs a token only for a published version of a panel the person’s account has installed, never for a version waiting for review and never for a deleted account. Until your version is approved, sign in from a loaded folder with development tokens.

Signing someone in

app.jsjs
const API = 'https://api.nook.app'

// Every request carries a fresh token; your server checks it each time
async function call(path, body) {
  const { token } = await deska.account.token()
  const res = await fetch(API + path, {
    method: 'POST',
    headers: { authorization: `Bearer ${token}`, 'content-type': 'application/json' },
    body: JSON.stringify(body),
  })
  if (!res.ok) throw new Error(`The server answered ${res.status}`)
  return res.json()
}

// Who is here: both fields are optional, the person may untick them or have
// no photo. Keep your data under sub, never the username: a username can change
function showProfile({ username, avatar }) {
  profileName.textContent = username ? '@' + username : 'Signed in'
  profilePhoto.hidden = !avatar
  if (avatar) profilePhoto.src = avatar // an <img>: draw it, never download or keep it
}

signInButton.addEventListener('click', async () => {
  try {
    const me = await deska.account.signIn({ username: true, avatar: true })
    showProfile(me)
    showBoard(await call('/session', {}))
  } catch (err) {
    if (err.code === 'declined') return // closed the sheet: Deska asks again once they come back to the panel
    if (err.code === 'not_signed_in') say('Sign in to Deska, then try again.')
    else if (err.code === 'permission_denied') say("Turned off on this panel's page in Deska.")
    else say('Could not sign in right now.')
  }
})

// After a reload: no sheet. token() answers permission_denied when the Deska
// account signed in now never pressed Continue for this panel on this computer
const init = await deska.ready()
try {
  if (!init.permissions.includes('account')) throw new Error('Not allowed yet')
  showBoard(await call('/session', {}))
} catch {
  showSignIn()
}

deska.on('account', ({ signedIn }) => {
  if (!signedIn) showSignIn() // they stopped it from Deska or deska.dev
})

deska.account.signIn({ name, email, username, avatar })

Call it straight from a press in your panel. The first time, Deska asks with its sheet, its Continue armed after half a second. Once the person allowed it, signIn answers at once, without a sheet, unless it asks for a field not shared yet: then a smaller sheet, Share more with <panel>?, asks for just those, and Cancel there answers with what was shared before. The username comes from the person’s Deska profile. The avatar is an https URL on Deska’s own photo proxy, opaque and independent of the username, never Clerk’s or Google’s address, and is absent when the account hides its photo or has none. The URL is checked against the active avatar grant on every request and is private and uncached: do not persist or share it. Account panels may draw that photo path without declaring deska.dev as a network host.

Cancel keeps nothing, but Deska shows no new sheet until the person leaves your panel and comes back to it (a click in it, a switch back to Deska). Until then, signIn answers as that Cancel did, without a sheet: declined, or for a Share more question the token with what was shared before. So a page can never ask again under the person’s next keys. The person stops a panel asking by turning account off on its page in the Marketplace; from then on both calls answer permission_denied without asking.

Allowing is kept for the install, but a sign-in belongs to one Deska account. Another Deska account signed in on the same computer gets its own first sheet from signIn, and token() answers permission_denied for it until it pressed Continue.

Deska tells deska.dev when the person pressed Continue, and only that starts a sign-in, or starts a stopped one again. Your page does nothing for it.

When Continue cannot finish, the sheet stays open and says why: deska.dev could not sign right now or could not be reached, too many sign-ins, the account’s install list on deska.dev does not have the panel yet (with Try again), the version is not one deska.dev signs for, the Deska account was deleted, or the Deska account changed while Deska asked, so nothing was kept. Your call answers host_error once the person closes the sheet.

ArgumentTypeNotes
namebooleanOptional. Ask for the person’s name. The sheet offers a box for it, unticked.
emailbooleanOptional. Ask for the person’s email, the same way.
usernamebooleanOptional. Ask for the username of their Deska profile, with its own unticked box.
avatarbooleanOptional. Ask for their profile photo, with its own unticked box. It is shared only while the account shows a photo.
Permission
account
Returns
{ token, expiresAt, sub, name?, email?, username?, avatar? }: the token, when it expires in milliseconds since the epoch, the person’s id for your panel, and each profile field only when the person ticked it.
Limits
  • 30 tokens a minute per account, for every panel together.
ErrorWhen
not_focusedThe panel does not have focus. Call it from a press.
declinedThe person pressed Cancel or closed the sheet, or another of Deska’s questions is open. After a Cancel, the same until the person leaves the panel and comes back to it.
permission_deniedpanel.json does not ask for account, or the person turned it off on the panel’s page or stopped it.
not_signed_inDeska itself is signed out.
host_errordeska.dev could not sign a token for this version, the account’s install list on deska.dev does not have the panel yet, the Deska account was deleted, or the Deska account changed while Deska asked. The sheet said why before the person closed it.

Getting a fresh token

deska.account.token()

Never asks the person. A token lasts ten minutes, and Deska hands back the same one while it has more than a minute left, so call token() before each request to your server instead of keeping one. Never store a token in deska.storage.

Permission
account
Returns
The same shape as signIn, with what the person shares, valid for at least another minute.
ErrorWhen
permission_deniedThe person has not allowed it yet, turned it off or stopped it (here, on another computer or on deska.dev), or the Deska account signed in now never pressed Continue for this panel on this computer.
not_signed_inDeska itself is signed out.
rate_limitedMore than 30 tokens this minute for the account.
host_errordeska.dev could not sign right now.

Once the person allowed it, init.permissions includes account, so a page that reloads knows it may ask for a token without a press. That is the install’s answer: under another Deska account, token() may still answer permission_denied, so show your Sign in button then. When the person stops it, from the panel’s page in Deska or on deska.dev, every open copy of the panel hears account with { signedIn: false }; it hears { signedIn: true } when they sign in again.

A stop on another computer or on deska.dev reaches this one when Deska next checks the account’s sign-ins, or when deska.dev refuses Deska’s next refresh of a token. Either way Deska stops it here: token() answers permission_denied and your page hears account { signedIn: false }.

Checking the token on your server

The token is a JWT signed with ES256. Its public keys are at https://deska.dev/.well-known/jwks.json, and any JWT library checks it. This example uses jose in Node:

server.jsjs
// npm install jose
import { createRemoteJWKSet, jwtVerify } from 'jose'

const JWKS = createRemoteJWKSet(new URL('https://deska.dev/.well-known/jwks.json'))
// Your package id in production; your loaded folder's dev key while you build
const AUDIENCE = process.env.DESKA_AUDIENCE ?? 'nook'
const PRODUCTION = process.env.NODE_ENV === 'production'

export async function verifyDeskaToken(token) {
  const { payload } = await jwtVerify(token, JWKS, {
    issuer: 'https://deska.dev',
    audience: AUDIENCE,
    algorithms: ['ES256'],
    typ: 'JWT', // a sign-in token; an event (secevent+jwt) is refused here
    requiredClaims: ['sub', 'exp'], // exp must be there, and jose refuses it once past
  })
  if (payload.dev === true && PRODUCTION) throw new Error('A development token')
  return payload // payload.sub is the person's id for your panel
}

// Express: POST /session with "authorization: Bearer <token>"
app.post('/session', async (req, res) => {
  try {
    const claims = await verifyDeskaToken(req.get('authorization')?.replace(/^Bearer /, ''))
    const account = await findOrCreateAccount(claims.sub) // your own code, keyed on sub
    res.json({ account: account.id })
  } catch {
    res.status(401).json({ error: 'not_signed_in' })
  }
})
ClaimWhat it holds
isshttps://deska.dev
audYour package id. Refuse any other: a token for another panel is not for you.
subThe person’s id for your panel. It never changes for that person and that panel.
iatWhen deska.dev signed it, in seconds.
expTen minutes after iat.
jtiUnique for each token.
nameOnly when the person shared their name.
email, email_verifiedOnly when the person shared their email.
usernameOnly when the person shared their Deska username.
avatarOnly when the person shared a visible profile photo: its URL on Deska’s photo proxy.
devOnly on a development token: true.
  • Check the signature against the key set by the token’s kid, the algorithm ES256, the header’s typ is JWT, iss, aud equal to your package id, and that exp is there and not past. jose does each of these with the options above. The typ check keeps an event, which deska.dev signs with the same keys, from ever passing as a sign-in.
  • Key the person’s account on sub, never on the email: the email may change, and you receive it only when they share it.
  • Your page’s origin is opaque, so your server must answer CORS for any origin (Access-Control-Allow-Origin: *, and allow the authorization header). Send the token in a header, not in a cookie: a panel keeps no cookies.
  • Keys rotate. deska.dev publishes the next key in the set at least an hour before it signs with it, and keeps the old one there at least an hour after. Look keys up by kid, and fetch the set again when a token names a kid you do not have (jose’s createRemoteJWKSet does), and never paste a key into your code.

Development tokens

A folder you load in Build a panel signs in with development tokens. Their aud is the folder’s own key, dev- and twelve hex characters, never the id its panel.json claims, and they carry "dev": true. A folder that copies a real panel’s id therefore can never sign anyone in to that panel’s server.

  • The key is init.panel.id in the loaded folder, and stays the same while the folder stays where it is. Accept it as the audience on your development server only.
  • Refuse a token with dev: true in production, as the example above does.
  • deska.dev keeps no record of development sign-ins and sends no events for them.
  • A page on localhost (your dev server) cannot sign in: it has no key deska.dev signs for. Load the folder instead.

When someone stops

A person stops signing in to your panel from its page in Deska or from Panels you signed in to on their deska.dev account page. When they do, or when they delete their Deska account, deska.dev posts an event to the events address of the version that last asked:

  • An HTTPS POST whose whole body is a Security Event Token (RFC 8417), a JWT with Content-Type: application/jwt, signed with the same keys, whose header typ is secevent+jwt. Accept an event only with that typ and an exp that has not passed, and never take one for a sign-in.
  • Its claims: iss, aud (your package id), iat, exp (five minutes after iat), jti and events. There is no sub at the top: the person’s id is inside the event.
  • events holds one key. https://deska.dev/events/panel-sign-in/revoked means they stopped signing in to your panel. https://deska.dev/events/panel-sign-in/account-deleted means they deleted their Deska account; it reaches every panel they ever signed in to, stopped ones included. Either one is { "sub": "<their id for your panel>" }.
  • A 2xx answer delivers it. deska.dev follows no redirect, waits 10 seconds at most, and tries again with a growing wait, from one minute up to four hours, for 24 hours. Each attempt is signed again with a fresh iat and exp but the same jti: drop one you have seen.
server.jsjs
const REVOKED = 'https://deska.dev/events/panel-sign-in/revoked'
const DELETED = 'https://deska.dev/events/panel-sign-in/account-deleted'

// Express: the "events" address in panel.json. The whole body is the JWT.
app.post('/deska/events', express.text({ type: 'application/jwt' }), async (req, res) => {
  let event
  try {
    const { payload } = await jwtVerify(req.body, JWKS, {
      issuer: 'https://deska.dev',
      audience: AUDIENCE,
      algorithms: ['ES256'],
      typ: 'secevent+jwt', // an event, never a sign-in token
      requiredClaims: ['jti', 'exp', 'events'], // exp is five minutes after iat
    })
    event = payload
  } catch {
    return res.sendStatus(400)
  }
  // Your own code: markSeen answers false for a jti it saw before
  if (await markSeen(event.jti)) {
    if (event.events[REVOKED]) await endSessions(event.events[REVOKED].sub)
    if (event.events[DELETED]) await deleteAccount(event.events[DELETED].sub)
  }
  res.sendStatus(204)
})

On revoked, stop treating that sub as signed in. On account-deleted, delete what your server keeps for it.

What you owe the people who sign in

  • A privacy policy at the address in panel.json that says what your server keeps and why.
  • A way to delete their account and what you keep, from inside your panel or your site, and deleting it when account-deleted arrives. Stopping is not deleting: after revoked, keep what they made only as your policy says.
  • Ask for the name, email, username or photo only when the panel uses it, and say why near the button.
  • Never draw a password form or a sign-in page, and never ask for a Deska password or code.
  • Never pass the token, id, name, email, username or photo to anyone else.

What each case answers

CasesignIntoken
AllowedA token, without a sheetA token
Not asked yetDeska’s sheetpermission_denied
Turned off on the panel’s page, or stoppedpermission_deniedpermission_denied
Cancel, Escape or the close buttondeclined, and nothing is kept. On a question for more: a token with what was shared before. The same, without a sheet, until the person leaves the panel and comes back to it.
Allowed for the install, but the Deska account signed in now never pressed Continue for it hereDeska’s sheet, as a first sign-inpermission_denied
Another of Deska’s questions is opendeclined
The panel does not have focusnot_focused
Deska is signed outnot_signed_innot_signed_in
deska.dev refused or could not sign (a version not published, a panel not on the account’s install list yet, a deleted account), or the Deska account changed while Deska askedhost_error, once the person closes the sheet, which says whyhost_error
Stopped on another computer or on deska.devpermission_denied, once Deska stopped it herepermission_denied