sdk.Auth()
The Auth helper implements the OpenID Connect login flow and token verification. It is a singleton created by initScenid. You do not construct it.
const auth = sdk.Auth()
For a walkthrough see User login and Verify tokens.
beginFlow({ redirectUri, state, scope })
Returns the authorization URL to redirect the user to. Synchronous.
| Parameter | Description |
|---|---|
redirectUri | Must match a redirect URI of the app |
state | Opaque value you verify in the callback (CSRF protection) |
scope | Default openid profile email offline_access |
const url = sdk.Auth().beginFlow({ redirectUri: 'http://localhost:3000/callback', state })
completeFlow(code, redirectUri)
Exchanges the authorization code. Resolves { idToken, refreshToken, user }.
| Field | Description |
|---|---|
idToken | ID token (or the access token if none was issued) |
refreshToken | Present if the offline_access scope was granted. Valid 12 hours |
user | Decoded payload of idToken |
Errors: auth/complete-flow-failed: <status> <body>, auth/complete-flow-no-token.
refreshFlow(refreshToken)
Returns the same shape as completeFlow, using the refresh token.
Errors: auth/refresh-flow-failed: <status> <body>, auth/refresh-flow-no-token. Server codes: oauth/invalid-refresh-token, oauth/client-mismatch, oauth/account-pending, oauth/account-denied, oauth/account-deactivated.
verify(idToken)
Verifies the RS256 signature via the JWKS, the issuer and the expiry. Resolves the payload.
| Error | Meaning |
|---|---|
sdk/invalid-token-format | Not a JWT |
auth/jwks-key-not-found | kid unknown |
auth/jwks-fetch-failed: <status> | Could not load the keys |
auth/invalid-signature | Signature does not match |
auth/invalid-issuer | iss differs from the service key issuer |
auth/token-expired | exp in the past |
The JWKS is cached for one hour. aud is not checked.
middleware()
Express middleware. Sets req.user (user tokens) or req.serviceClient (service tokens) when a valid Bearer token is present. Always calls next(). See Verify tokens.
clearExchangeCache(sub)
Drops the cached user tokens for a user, call it on logout.
exchangeToken(idToken) and getServiceToken()
Called automatically by asUser and asAdmin. You rarely need them directly.
exchangeToken: RFC 8693 token exchange, cached persub:client_id, expires 60 seconds early.getServiceToken:client_credentialsgrant, cached perclient_id, expires 30 seconds early.
Errors: auth/exchange-failed: <status> <body>, oauth/token-request-failed: <status> <body>.
AuthenticationError
extends Error, message auth/unauthorized, httpCode = 401. Thrown by the guards.