scute.tokens.verify checks an access token locally and returns a Scute::Session. It needs only the app id: the signing keys come from the app's public JWKS.
scute = Scute::Client.newsession = scute.tokens.verify(token)session.user_id # the Scute app user idsession.impersonated? # true when someone (support) is signed in as this usersession.actor # who, when impersonated: { "kind" => "backend", "email" => "support@acme.com" }What is checked#
- The token is a JWT with three parts and JSON header and claims. Otherwise :malformed.
- The algorithm is RS256. Anything else, including alg: none, is :algorithm.
- The signature matches one of the app's keys from GET /v1/auth/:app_id/.well-known/jwks.json. The key is picked by kid when the token has one. Otherwise :signature.
- exp is present (else :malformed) and not more than 30 seconds in the past (else :expired).
- aid is this app's public id (app_...). Otherwise :wrong_app.
- The token is a user's session: it has a uuid claim and no m2m claim. Otherwise :not_a_user.
Every failure raises Scute::InvalidToken with reason set to the symbol. An empty or nil token is :missing.
begin session = scute.tokens.verify(token)rescue Scute::InvalidToken => e e.reason # :missing, :malformed, :algorithm, :signature, :expired, :wrong_app, :not_a_user, :revokedendRevoked sessions#
Local verification cannot see a session that was revoked after the token was issued. Pass remote: true where that matters. The SDK then also calls GET /v1/auth/:app_id/current_user with the token (one call). A 401, 403 or 404 answer raises Scute::InvalidToken with reason :revoked. Other API errors raise Scute::APIError.
session = scute.tokens.verify(token, remote: true)Key cache#
| Constant | Value | Meaning |
|---|---|---|
| Scute::Tokens::KEYS_TTL | 600 | Keys are re-read every 10 minutes. |
| Scute::Tokens::REFETCH_AFTER | 60 | On a signature that matches no cached key, keys are re-read at most once a minute (key rotation). |
| Scute::Tokens::LEEWAY | 30 | Seconds of clock skew allowed on exp. |
The cache lives on the Tokens object, so reuse one client. A copy made with with_client_ip after the first tokens call shares it.
The session#
Scute::Session is an immutable Data object.
| Method | Returns |
|---|---|
| impersonated? | true when the imp claim is true. |
| authz_context | { "impersonated" => true, "actor" => ... } for an impersonated session, otherwise {}. Pass it as context: to authz.check so permissions marked "not while impersonating" are refused. |
App id#
scute.tokens.public_app_id returns the id the app's tokens carry. When app_id already starts with app_ it is returned as is. Otherwise the SDK reads it once from GET /v1/apps/:app_id and caches it.
In a controller#
Scute::Authentication reads the token from the request and calls verify for you. See Rails integration.