Taxum / @taxum/jwt / JwtLayer
Class: JwtLayer
Defined in: jwt/src/index.ts:50
A layer to validate incoming JWTs.
If verification succeeds, the decoded JWT is stored in the request's extensions under the JWT key.
The service will throw an UnauthorizedError if the JWT is missing or is not valid, unless allowUnauthorized
is set to true
.
Example
import {JwtLayer} from "@taxum/jwt";
import {m, Router} from "@taxum/core/routing";
const router = new Router()
.route("/" m.get(() => "I'm protected!"))
.layer(new JwtLayer(new Uint8Array());
See
Implements
Constructors
Constructor
new JwtLayer(
key
):JwtLayer
Defined in: jwt/src/index.ts:61
Creates a new JwtLayer.
Parameters
key
Uint8Array
<ArrayBufferLike
> | CryptoKey
| KeyObject
| JWK
Returns
JwtLayer
See
Methods
allowUnauthorized()
allowUnauthorized(
allow
):this
Defined in: jwt/src/index.ts:87
Sets whether to allow unauthorized requests.
If set to true
, unauthorized requests will be passed through to the inner service without setting the JWT extension.
Parameters
allow
boolean
Returns
this
debug()
debug(
enabled
):this
Defined in: jwt/src/index.ts:98
Sets whether to expose error details in the response body.
This can be helpful to debug issues with the configuration, but must not be enabled in production!
Parameters
enabled
boolean
Returns
this
layer()
layer(
inner
):HttpService
Defined in: jwt/src/index.ts:103
Wrap the given service with the middleware, returning a new service that has been decorated with the middleware.
Parameters
inner
Returns
Implementation of
verifyOptions()
verifyOptions(
verifyOptions
):this
Defined in: jwt/src/index.ts:76
Sets the verify options.
The options can either be static options or a function which returns the options.
Parameters
verifyOptions
JWTVerifyOptions
| () => JWTVerifyOptions
Returns
this