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:
- The person presses a button in your panel, and the page calls
deska.account.signIn(). - 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.
- The page receives a token that deska.dev signed. It sends it to your server.
- 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.
What to declare
{
"permissions": ["account"],
"network": ["api.nook.app"],
"account": {
"privacy": "https://nook.app/privacy",
"events": "https://api.nook.app/deska/events"
},
"sdk": 4
}- The permission
accountand anaccountobject, 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 yournetworkhosts. 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
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.
| Argument | Type | Notes |
|---|---|---|
name | boolean | Optional. Ask for the person’s name. The sheet offers a box for it, unticked. |
email | boolean | Optional. Ask for the person’s email, the same way. |
username | boolean | Optional. Ask for the username of their Deska profile, with its own unticked box. |
avatar | boolean | Optional. 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.
| Error | When |
|---|---|
not_focused | The panel does not have focus. Call it from a press. |
declined | The 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_denied | panel.json does not ask for account, or the person turned it off on the panel’s page or stopped it. |
not_signed_in | Deska itself is signed out. |
host_error | deska.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.
| Error | When |
|---|---|
permission_denied | The 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_in | Deska itself is signed out. |
rate_limited | More than 30 tokens this minute for the account. |
host_error | deska.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:
// 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' })
}
})| Claim | What it holds |
|---|---|
iss | https://deska.dev |
aud | Your package id. Refuse any other: a token for another panel is not for you. |
sub | The person’s id for your panel. It never changes for that person and that panel. |
iat | When deska.dev signed it, in seconds. |
exp | Ten minutes after iat. |
jti | Unique for each token. |
name | Only when the person shared their name. |
email, email_verified | Only when the person shared their email. |
username | Only when the person shared their Deska username. |
avatar | Only when the person shared a visible profile photo: its URL on Deska’s photo proxy. |
dev | Only on a development token: true. |
- Check the signature against the key set by the token’s
kid, the algorithm ES256, the header’stypisJWT,iss,audequal to your package id, and thatexpis there and not past. jose does each of these with the options above. Thetypcheck 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 theauthorizationheader). 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 akidyou do not have (jose’screateRemoteJWKSetdoes), 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.idin 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: truein 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 headertypissecevent+jwt. Accept an event only with thattypand anexpthat has not passed, and never take one for a sign-in. - Its claims:
iss,aud(your package id),iat,exp(five minutes afteriat),jtiandevents. There is nosubat the top: the person’s id is inside the event. eventsholds one key.https://deska.dev/events/panel-sign-in/revokedmeans they stopped signing in to your panel.https://deska.dev/events/panel-sign-in/account-deletedmeans 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
iatandexpbut the samejti: drop one you have seen.
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-deletedarrives. Stopping is not deleting: afterrevoked, 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
| Case | signIn | token |
|---|---|---|
| Allowed | A token, without a sheet | A token |
| Not asked yet | Deska’s sheet | permission_denied |
| Turned off on the panel’s page, or stopped | permission_denied | permission_denied |
| Cancel, Escape or the close button | declined, 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 here | Deska’s sheet, as a first sign-in | permission_denied |
| Another of Deska’s questions is open | declined | |
| The panel does not have focus | not_focused | |
| Deska is signed out | not_signed_in | not_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 asked | host_error, once the person closes the sheet, which says why | host_error |
| Stopped on another computer or on deska.dev | permission_denied, once Deska stopped it here | permission_denied |