requireBearerAuth or optionalBearerAuth. The middleware calls it on each request to validate the bearer token before any tool runs.
Example
verifyAccessToken validates the token however your provider requires, returns an AuthInfo for a valid token, and throws InvalidTokenError otherwise. Pass it to the middleware as verifier: { verifyAccessToken }.
How you validate the token depends on your provider. Check its docs.
verifyAccessToken
- Resolve with an
AuthInfofor a valid token. The middleware puts it onextra.authInfofor tool handlers. - Throw
InvalidTokenErrorfor a malformed, badly signed, or expired token. The middleware returns a 401 with the rightWWW-Authenticateheader.
requiredScopes against authInfo.scopes and returns a 403 on a missing scope.
createJwksVerifier
OAuthConfig. jwksUri defaults to ${issuer}/.well-known/jwks.json, and omitting audience skips the audience check, for IdPs that bind none.
Verified claims land in extra with sub renamed to subject, while client_id, scope and exp become AuthInfo fields.
AuthInfo
What verifyAccessToken resolves with for a valid token.
extra is an untyped bag by default. Pass the claims your verifier resolves with (Promise<AuthInfo<Claims>>) and handlers receive that shape, since the type travels with the verifier into the server.
requireBearerAuth
Require a token on every request
optionalBearerAuth
Accept a token when present, allow anonymous otherwise
Authenticate Users
Add sign-in to your app end to end