jwtAuthentication function

Middleware jwtAuthentication(
  1. JwtOptions options, {
  2. AuthJwtVerifiedCallback<EngineContext>? onVerified,
  3. Client? httpClient,
})

Creates a JWT authentication Middleware with the given options.

Disabled options pass through to next. Enabled middleware reads the configured header and bearer prefix, verifies the token, and writes its claims, subject, header, and authentication attributes to the request before invoking onVerified and then next. httpClient is used for remote key material. A JwtAuthException becomes a generic 401 response with a sanitized WWW-Authenticate bearer challenge rather than escaping the middleware.

Implementation

Middleware jwtAuthentication(
  JwtOptions options, {
  AuthJwtVerifiedCallback<EngineContext>? onVerified,
  http.Client? httpClient,
}) {
  return jwtAuthenticationWithVerifier(
    JwtVerifier(options: options, httpClient: httpClient),
    onVerified: onVerified,
  );
}