Backend requirements
Authyra works with most token APIs. These choices on the server side make sessions reliable.
Return lifetimes
Send expires_in with every access token. Without it, Authyra cannot refresh ahead of time and relies on 401 responses alone, which makes the first request after expiry slower.
If your refresh tokens expire, say when (refresh_token_expires_in, or an absolute date) and map it to refreshTokenExpiresAt. Authyra then refreshes before the deadline so an idle app keeps its session.
Answer the refresh endpoint precisely
| Situation | Respond with |
|---|---|
| Refresh token unknown, expired, revoked or reused | 401, or 400 with {"error": "invalid_grant"} |
| Anything temporary: database down, rate limit, deploy | 5xx or 429, never 401 |
The provider turns the first case into RefreshRevokedException, which ends the session. A 401 sent for a temporary problem signs users out for no reason.
Rotate refresh tokens
Issuing a new refresh token on every refresh, and invalidating the old one, limits what a stolen token can do. Authyra makes rotation safe on the client: one refresh at a time, always with the latest token.
Reuse detection (revoking the whole session when an old refresh token comes back) is the strongest setting. A short grace period is a reasonable trade-off for clients you do not control, but not needed for Authyra.
Revoke on sign-out
Expose an endpoint that invalidates a refresh token, and call it from your provider's signOut. Make it idempotent: revoking an unknown token returns success.
Keep user ids stable
The session key is the provider id plus the user id you return. Changing a user's id, or returning an email that can change, creates a second session for the same person.
Verify identity tokens on the server
For Google and Apple, the app sends an identity token to your backend. Verify its signature, audience, issuer and expiry before creating a session. The device never verifies tokens for you.