Skip to main content
A verifier is the provider-specific token check you implement and pass to 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

The verifier’s only required method.
  • Resolve with an AuthInfo for a valid token. The middleware puts it on extra.authInfo for tool handlers.
  • Throw InvalidTokenError for a malformed, badly signed, or expired token. The middleware returns a 401 with the right WWW-Authenticate header.
Do not check scopes here: the middleware enforces requiredScopes against authInfo.scopes and returns a 403 on a missing scope.

createJwksVerifier

Builds a verifier that validates JWTs against a remote JWKS. The providers use it internally; call it yourself when hand-building an 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