prufy
Skip to the page

APIAuthentication

API

Authentication

There's no sign-up and no key to create. Your first claim starts a session, and the cookie it sets is what makes that claim yours.

Sessions without sign-up

A request with no session can do one thing that matters: create a claim. When it does, the server makes an account, starts a session for it, and sets the prufy_session cookie on the response. From then on, that cookie is the credential.

The domain is checked before any of that happens, so a typo doesn't leave an empty account behind. A request that already has a session keeps it: claiming a second domain adds to the same account.

curl -X POST 'https://www.prufy.dev/api/v1/claims' \
  -c cookies.txt -b cookies.txt \
  -H 'content-type: application/json' \
  -d '{
  "input": "yourcompany.com"
}'

One network can start 10 new sessions an hour. After that, creating a claim without a cookie answers rate_limited until the oldest one ages out. A client that keeps its cookie never meets this limit.

Carrying the session

Send the cookie back on every later request. A browser does this by itself for same-origin requests. From code, each tool has its own way: curl reads and writes a cookie jar, Python's requests.Session remembers cookies, and Node's fetch has to be handed the header.

curl 'https://www.prufy.dev/api/v1/claims/clm_4b1f7c1e-52e7-4c0a-9a3b-7d2f0c6e8a10' \
  -b cookies.txt

Without the cookie, a route that needs one answers 401. A cookie that's malformed or that we never issued gets the same answer.

No session401 Unauthorized
{
  "error": {
    "kind": "unauthorized",
    "message": "This browser isn't signed in to any domains yet."
  }
}

A claim that belongs to another account answers 404 not_found, exactly like one that doesn't exist. There's no way to tell from the outside whether an id is real.

AttributeValueWhy
Nameprufy_sessionOne cookie, holding one random token of 43 characters.
HttpOnlyAlwaysScripts on the page can't read it, so an injected script can't take it.
SameSiteLaxAnother site can't make a signed-in POST. This is the CSRF protection.
SecureOver HTTPSOn production it never travels in the clear.
Max-Age400 daysThe longest a browser will keep a cookie. The session ends then too.
Path/Sent to every route.

The token is 256 random bits and it's never stored. The database keeps its SHA-256 hash, which is enough to find the session and useless for signing in, so a leaked database doesn't leak sessions.

Signing in on another device

An account with a confirmed alert address can be reached from anywhere. Request a sign-in link with that address, and we email a link that works once, for 15 minutes. It opens a page with a button. Pressing it makes that device one more session on the same account, with its own cookie.

curl -X POST 'https://www.prufy.dev/api/v1/sign-in' \
  -H 'content-type: application/json' \
  -d '{
  "email": "owner@yourcompany.com"
}'
  • The answer never says who has an account. Every address gets the same { requested: true }, and the email is sent after the response, so the timing doesn't say either.
  • Only a confirmed address works. Typing an address into the alerts form doesn't make it one, and a link stops working if the address is changed or removed before it's used.
  • Opening the link does nothing by itself. Mail scanners open every link, so the page asks for a press, and the press is a POST.
  • Nothing moves between accounts. A device that was signed in to a different account ends that session. Its claims stay where they were.

A terminal can't press a button, so prufy login asks for the link with the SHA-256 of a secret it keeps. Pressing that link's button shows a code instead of signing the browser in. The terminal sends the code and its secret to Redeem a sign-in code, and gets its session in Set-Cookie. The code lasts 10 minutes, and the session token never appears in a URL or on the page.

Signing out

Sign out ends the session that sends it, on the server, and clears the cookie. Only that one: the account, its claims and its other devices are untouched. Repeating it is safe. Sign out everywhere else ends every other session on the account, for a lost phone or a token that leaked.

curl -X DELETE 'https://www.prufy.dev/api/v1/session' \
  -b cookies.txt

Tokens that stand in for one

Four things have to work for someone who has no session, often on a different device. Each uses a token that does one job and nothing else.

TokenWhere it goesWhat it can doHow long
Setup linkThe path of /api/setup/{token}See one claim's record and run a check. Nothing else.30 days
Email confirmationThe body of Confirm the alert emailConfirm one address, once.24 hours
UnsubscribeThe query of Unsubscribe from alert emailsStop alert emails to one address.Until the address changes
Sign-in linkThe body of Use a sign-in linkStart one session on the account whose alert address it went to, once.15 minutes

A setup link is safe to forward for exactly that reason. Whoever holds it can add the record and ask us to look, and can't get a new code, stop the claim or see its history.

What each route needs

What isn't here yet

  • API keys. A long-lived secret you create once and send as a header. Until they exist, a server-side integration has to keep the cookie from its first claim.
  • Passkeys. Signing in without an inbox in between. Sign-in links need a confirmed address first.

Both are planned and tracked in the project's issues.