Skip to content

Documents for @litert/jwt / Validators/Subject / JwtSubjectValidator

Class: JwtSubjectValidator ​

Defined in: src/lib/Validators/Subject.ts:71

The validator to check if the sub claim is allowed.

Example ​

ts
import * as LibJwt from '@litert/jwt';
const info = LibJwt.parse(token);

const validator = new LibJwt.JwtSubjectValidator({
    allowlist: [
        'trusted-subject',
        /^https://trusted\.domain/.+$/,
        (sub: string) => sub.endsWith('@trusted.com'),
    ],
});

validator.validate(info);

Implements ​

Constructors ​

Constructor ​

new JwtSubjectValidator(opts): JwtSubjectValidator

Defined in: src/lib/Validators/Subject.ts:81

Parameters ​

opts ​

ISubjectValidationOptions

Returns ​

JwtSubjectValidator

Properties ​

name ​

readonly name: string

Defined in: src/lib/Validators/Subject.ts:73

The name of the validator.

When using with the JwtVerifier class, this name can be used to identify which validator failed.

Implementation of ​

IJwtValidator.name

Methods ​

validate() ​

validate(parsed): void

Defined in: src/lib/Validators/Subject.ts:99

Validate the provided parse result of a JWT, checking if the JWT is valid.

Parameters ​

parsed ​

IJwtParseResult

Returns ​

void

Throws ​

If validation failed or an error occurred inside.

Implementation of ​

IJwtValidator.validate