Tokens & sessions
How Spica issues and verifies JWTs for identities and users, how refresh tokens extend sessions, and how to revoke them.
Access tokens
A successful login returns a JWT signed with the API's passport-secret:
{"scheme": "USER", "token": "eyJhbGciOiJIUzI1NiIs..."}Send it as Authorization: <scheme> <token>. The payload of a user token looks like this:
{
"_id": "6b0b1adea5611972c29c2631",
"username": "reader1",
"policies": ["6b0b1aeba5611972c29c2635"],
"lastLogin": "2026-11-28T18:18:06.100Z",
"iat": 1795889886,
"exp": 1796062686,
"aud": "spica.io",
"iss": "https://api.example.com/api"
}Lifetime
| Option | Identities | Users |
|---|---|---|
| Default lifetime | --passport-identity-token-expires-in (2 days) | --passport-user-token-expires-in (2 days) |
| Maximum a client may request | --passport-identity-token-expiration-seconds-limit | --passport-user-token-expiration-seconds-limit |
Clients can ask for a shorter or longer token with expires (seconds) in the login body, up to the maximum:
{"identifier": "spica", "password": "spica", "expires": 900}Refresh tokens
Login responses also set an HTTP-only cookie with a refresh token:
Set-Cookie: refreshToken=eyJ...; Max-Age=259200; Path=passport/identity/session/refresh; HttpOnly; Secure; SameSite=NoneWhen the access token expires, exchange it for a new one. Send the old access token in Authorization and the cookie with the request:
| Caller | Endpoint |
|---|---|
| Identity | POST /passport/identity/session/refresh |
| User | POST /passport/user/session/refresh |
const response = await fetch("https://api.example.com/api/passport/user/session/refresh", {
method: "POST",
credentials: "include",
headers: {Authorization: `USER ${expiredToken}`}
});
const {token} = await response.json();Without the cookie the endpoint returns 401 with Refresh token does not exist.
| Option | Default |
|---|---|
--passport-identity-refresh-token-expires-in | 3 days |
--passport-user-refresh-token-expires-in | 3 days |
--refresh-token-hash-secret | Derived from the master key. Refresh tokens are stored hashed with it. |
Manage refresh tokens
Administrators can list and revoke sessions:
| Endpoint | Action | Purpose |
|---|---|---|
GET /passport/refresh-token | passport:refresh-token:index | List sessions. |
GET /passport/refresh-token/:id | passport:refresh-token:show | Get one. |
PUT /passport/refresh-token/:id | passport:refresh-token:update | Disable or enable it: {"disabled": true}. |
DELETE /passport/refresh-token/:id | passport:refresh-token:delete | Delete it. |
[{"_id": "6b0b1924a5611972c29c25f1", "identity": "6b0b191d988a814684c8fec2", "created_at": "2026-11-28T18:10:44.019Z", "expired_at": "2026-12-01T18:10:44.019Z", "last_used_at": null}]
Verify a token
Decode and verify a token on your own backend:
| Caller | Endpoint |
|---|---|
| Identity | GET /passport/identity/verify |
| User | GET /passport/user/verify |
Send the raw token, without the scheme, in the Authorization header. A valid token returns its payload, an invalid one returns 400.
curl https://api.example.com/api/passport/user/verify -H "Authorization: eyJhbGciOiJIUzI1NiIs..."Inside functions, use Auth.verifyToken from @spica-devkit/auth or Identity.verifyToken from @spica-devkit/identity.
Revoke access
| Goal | How |
|---|---|
| End one session | Disable or delete its refresh token. The current access token stays valid until it expires. |
| End every session of a user now | Set deactivateJwtsBefore on the user to the current Unix time. |
| Lock a user out | Set bannedUntil on the user. |
| Change what a token can do | Edit or detach policies. Changes apply to existing tokens immediately. |
| Invalidate every token of the instance | Rotate passport-secret. All users and identities must log in again. |
Best practices
- Keep access tokens short-lived (minutes to hours) and rely on refresh tokens for long sessions.
- Store access tokens in memory in browsers, and let the refresh cookie survive reloads.
- Never put tokens in URLs, except for WebSocket connections that can't send headers.
- Rotate
passport-secretonly as an emergency measure, because it signs everyone out.