Menu

Authentication and sessions

Public operations, session tokens, API keys and OAuth tokens; signing in without a password; strong authentication.

Each operation says who may call it, in x-weird-auth:

  • public: anyone, with no credential (signing in, the device login's first steps, the health check);
  • session: a person signed in, with a session access token;
  • key: an API key holding the permission the operation names in x-weird-scope, or a session;
  • oauth: an access token an OAuth client obtained.

Every credential is sent the same way: Authorization: Bearer <token>.

SchemeHow it is sentWhat it is
apiKeyAuthorization: Bearer …an API key token (weird_...), authenticating as its account within its granted scopes
oauthAccessTokenAuthorization: Bearer … (JWT)an OAuth access token obtained from /oauth/token by a registered client
refreshCookieAuthorization: undefined …a page's refresh cookie (HttpOnly, Secure, SameSite=Strict, Path=/auth, 30 days), set by a sign-in made with X-Weird-Session: cookie, read by POST /auth/refresh alone (with that header, from the application's own origin), rotated at each refresh and cleared by a sign-out
sessionTokenAuthorization: Bearer … (JWT)a session access token (the auth pair's access_token)
x-weird-authOperations
public — none: anyone may call it25
session — a session access token (a signed-in person, not an API key)9
key — an API key holding the permission below, or a session237
oauth — an OAuth access token1

Sessions#

There are no passwords. A person signs in with a code emailed to them:

  1. POST /auth/login/start with the email address emails a sign-in code of eight letters and digits, shown XXXX-XXXX, and answers a flow token (the answer is the same whether or not the address has an account);
  2. POST /auth/login/verify with that token, the emailed code (in any case, the dash optional) and, for an account with an authenticator, its current code (totp_code) or an unused backup code, answers the auth pair: access_token, refresh_token and the user. Too many wrong codes from one network in an hour answer 429 rate-limited for that network only: try again later or from another network.

The access token is valid for 7 days. The refresh token is valid for 30 days and can be used only once: POST /auth/refresh answers a new pair for the same session. Sending a refresh token that was already used ends the whole session, and the person must sign in again.

A terminal or another device without a browser signs in with the device login: POST /auth/device/start answers a code the person approves while signed in elsewhere (weird login --device does this). Sessions are listed and ended with the session operations; weird sessions and weird logout are the CLI's.

API keys#

An API key (weird_...) acts as its account within the permissions it was created with. It is made by a signed-in person, shown once, and cannot be changed: see API keys and permissions.

Strong authentication#

Some operations need more than a credential (x-weird-strong-auth):

  • none: nothing more;
  • recent-step-up: a caller signed in with a session needs an authenticator enrolled on the account (403 enrolment-required until one is) and a recent proof of it: the session was stepped up in the last 15 minutes (POST /auth/step-up, or a sign-in that carried the second factor), or the request body carries totp_code (a current authenticator code) or backup_code (an unused backup code). Without either the answer is 403 step-up-required: step up, then retry. A wrong or used code is 422 invalid-totp, and too many wrong codes are 429 rate-limited for a while. An API key is not asked for a second factor;
  • code-in-request: the code must be in the request body itself, from a session and an API key alike (a recent step-up is not enough). x-weird-code-in-request-when names the case when an operation asks for a code only sometimes.

The operations that spend credits or cannot be undone are the ones that need it; each operation's page says which.