jose/lib/jwt/shared_validations.js
Filip Skokan 6c98b61597 feat: validate JWTs according to a JWT profile - ID Token
It is now possible to pass a profile to `JWT.verify` and have the JWT
validated according to it. This makes sure you pass all the right
options and that required claims are present, prohibited claims are
missing and that the right JWT typ is used.

More profiles will be added in the future.
2019-07-23 14:50:16 +02:00

12 lines
388 B
JavaScript

const isNotString = val => typeof val !== 'string' || val.length === 0
module.exports.isNotString = isNotString
module.exports.isString = function isString (Err, value, label, required = false) {
if (required && value === undefined) {
throw new Err(`${label} is missing`)
}
if (value !== undefined && isNotString(value)) {
throw new Err(`${label} must be a string`)
}
}