Authorization header of every request to a protected endpoint.
Passing the token
Set theAuthorization header to Bearer <access_token>:
The header value must start with
Bearer (with a space). Any other prefix, or an absent header, returns a 401 Unauthorized error.Token response model
When you log in, Userverse returns the following token response inside adata envelope:
Always
"bearer". Use this value to confirm the token scheme before storing the token.A signed JWT to include in the
Authorization: Bearer header for protected endpoint calls. Expires at access_token_expiration.UTC timestamp when the access token expires, formatted as
YYYY-MM-DD HH:MM:SS. Controlled by jwt.TIMEOUT in your config (default: 30 minutes).A signed JWT you can use to obtain a new token pair without logging in again. Expires at
refresh_token_expiration.UTC timestamp when the refresh token expires, formatted as
YYYY-MM-DD HH:MM:SS. Controlled by jwt.REFRESH_TIMEOUT in your config (default: 60 minutes).Configuration
JWT behaviour is controlled by thejwt block in your config.json:
| Key | Description | Default |
|---|---|---|
SECRET | Secret key used to sign and verify tokens. Set a long, random value in production. | "secret1234" |
ALGORITHM | Signing algorithm. Userverse uses "HS256". | "HS256" |
TIMEOUT | Access token lifetime in minutes. | 30 |
REFRESH_TIMEOUT | Refresh token lifetime in minutes. | 60 |
Token type enforcement
Every JWT issued by Userverse contains atype claim in its payload. The server validates this claim on every request:
- All protected endpoints require
"type": "access". Sending a refresh token to a protected endpoint returns403 Forbidden.
PATCH /user/login to obtain a new token pair.
Common errors
| Status | Message | Cause |
|---|---|---|
401 Unauthorized | "Invalid request" | Missing Authorization header or header is not in Bearer <token> format |
401 Unauthorized | "Token has expired" | The access token has passed its expiration time |
401 Unauthorized | "Invalid token" | The JWT signature is invalid or the token is malformed |
403 Forbidden | "Invalid token for access token" | A refresh token was submitted to an access-token-protected endpoint (wrong token type) |
403 Forbidden | "Missing user data in token" | The token payload does not contain a user claim |
Next steps
Basic Auth
Learn how to obtain a token by logging in with HTTP Basic Auth.
API reference
See the full list of authentication endpoints with request and response schemas.