Authentication
PlayTelly signs you in through AuthAPI and then accepts the resulting access token on every API request. This page explains the parts you need to build an integration. For the first call, see the Quickstart.
Tokens¶
| Token | Lifetime (default) | Use |
|---|---|---|
| Access token | 15 minutes (900 s) | Send it on every API request |
| Refresh token | 7 days (168 h) | Exchange it for a new access token. It rotates: every refresh returns a new one |
The lifetimes are server settings and can differ on a self-hosted instance. The
sign-in response includes expires_in in seconds.
Web and non-web clients¶
AuthAPI treats clients differently, chosen by the PlayTelly-Platform header on
sign-in:
web(the default): tokens are set as cookies. You also send yourcompany_code.mobile: tokens come back in the response body. Use this for scripts, servers and apps.
Sending the token¶
Browser clients can rely on the access_token cookie instead.
Refreshing¶
Refresh when the access token is about to expire (before expires_in seconds pass), or when a request returns 401.
After a refresh, retry the failed request once; if it fails again, sign in again. The refresh token works once, so if
several parts of your client refresh at the same time only the first succeeds. Let one place in your client refresh
and share the result.
Request a new token pair like this:
curl -s -X POST "https://<AUTH_HOST>/api/v1/refresh" \
-H "Content-Type: application/json" \
-d '{"client_type": "mobile", "refresh_token": "<REFRESH_TOKEN>"}'
Replace <AUTH_HOST> with the AuthAPI host from API conventions and
<REFRESH_TOKEN> with the refresh token from sign-in or the previous refresh. You get a new token pair:
{
"access_token": "<ACCESS_TOKEN>",
"refresh_token": "<REFRESH_TOKEN>",
"expires_in": 900,
"token_type": "Bearer",
"org": { "org_id": "9b2e4d71-0c3a-4f8e-b6d2-5a1c7e9f3b20", "org_slug": "acme", "role": "ORG_ADMIN" }
}
Store the new refresh token: the old one stops working. Web clients send {"client_type": "web"} and get new
cookies instead. A 401 means the refresh token is no longer valid (expired, already used, or the account or
organization is no longer active): sign in again. Role changes take effect at the next refresh.
Sessions¶
Every sign-in creates a session that survives token refreshes. A user can list
their sessions and revoke one, all others, or all of them. Revoking a session stops it from
refreshing, but its current access token stays valid until it expires, which is
why access tokens are short-lived. To react at once, a client can listen to the
session event stream, which sends session_revoked when its session is ended elsewhere.
What the token says¶
The access token is a signed JWT (RS256). It carries the user ID (sub), the
session ID (sid) and the organization with the user's role in it (org.org_id,
org.role). Services verify it with AuthAPI's public keys
(https://<AUTH_HOST>/.well-known/jwks.json) instead of calling AuthAPI on each
request. Don't read permissions from the token: ask the Identity API.
Sign-in errors¶
| Status | Code | Meaning |
|---|---|---|
400 |
INVALID_REQUEST |
Username or password missing, or company_code missing on web |
401 |
INVALID_CREDENTIALS |
Wrong user name or password, or the user isn't a member of that organization |
403 |
ORG_PENDING, ORG_DISABLED, ACCOUNT_PENDING, ACCOUNT_DISABLED, ACCOUNT_INVITED |
The organization or account isn't active yet, or has been disabled |
404 |
ORG_NOT_FOUND |
The company code doesn't match an organization |
503 |
LICENSE_EXPIRED |
This instance's license has expired (self-hosted instances) |
An invited user activates their account with the invitation link instead of signing in. Every error code is in the Authentication API reference.
On an API request, 401 means the token is missing, expired or invalid, and 403
means you're signed in but your role lacks the permission the route needs.
Not documented yet¶
- How to read the exact roles and permissions a user has.
- The error body format on API routes outside AuthAPI (see API conventions).