JWT mode
Bearer access and refresh tokens for API clients.
Cookie sessions are the default. Set Config.JWT to issue short-lived Access
tokens and rotating Refresh tokens as well:
cfg.JWT = &signet.JWTConfig{
Algorithm: "HS256",
Key: key, // []byte for HS256
Issuer: "signet",
}Only HS256, RS256 and EdDSA are accepted, with a matching key type. Access Tokens
default to 15 minutes and Refresh Tokens to 30 days; TokenPair.ExpiresIn reports the
access lifetime in seconds.
POST /token exchanges credentials or a Refresh token for a TokenPair;
VerifyAccessToken validates a bearer token and returns its User.
Refresh tokens rotate on every use. Replaying a consumed Refresh token is treated
as theft: Signet revokes every Session and every kind of Token for that User and
returns ErrRefreshReuse.
Calling an exchange or verification method without Config.JWT returns ErrJWTDisabled.
Set JWTOnly for API-only applications: no session cookies are issued and no
CSRF key is required.
Second factor and /token
When a User has Second factor enabled, a password-only POST /token does not return tokens. It
returns {"two_factor_challenge": "...", "error": "two_factor_required"}. Post that challenge
with a TOTP code or Backup code to receive the Access/Refresh pair:
const first = await fetch('/token', {
method: 'POST', body: JSON.stringify({ email, password }),
});
const challenge = (await first.json()).two_factor_challenge;
const pair = await fetch('/token', {
method: 'POST', body: JSON.stringify({ challenge, code: '123456' }),
});The challenge is single-use and expires after five minutes. See Second factor.
Key rotation and JWKS
For rotation, set Keys instead of the legacy single Key. The first key signs and every key
verifies, so a deployment can prepend a new key and keep the old one until live tokens expire.
All keys must match Algorithm; a mixed or duplicate ring is rejected with
ErrInvalidKeyRing.
cfg.JWT = &signet.JWTConfig{
Algorithm: "RS256",
Keys: []any{newRSAKey, oldRSAKey},
Issuer: "signet",
}Client.JWKSHandler() is opt-in — mount it deliberately if clients need key discovery:
mux.Handle("/jwks.json", auth.JWKSHandler())It publishes only the public half of asymmetric keys with a stable kid, alg and use.
Symmetric HS256 keys are never published; with only HS256 configured the document has an empty
keys array. The handler is not part of Client.Handler().