import { isURL , ValidationArguments , ValidatorConstraint , ValidatorConstraintInterface , } from 'class-validator' ; import { MetadataIdpAdapterMongoDTO } from './identity-provider-adapter-mongo.dto' ; const symetricAlgs = [ 'HS256' , 'HS512' ] ; @ ValidatorConstraint ( { name : 'JwksUri' , async : false } ) export class JwksUriValidator implements ValidatorConstraintInterface { validate ( JwksUri , args ) { const { discovery , userinfo_signed_response_alg , id_token_signed_response_alg , } = args . object as MetadataIdpAdapterMongoDTO ; const isUserInfoAlgAsymetric = ! symetricAlgs . includes ( userinfo_signed_response_alg ) ; const isIdTOkenAlgAsymetric = ! symetricAlgs . includes ( id_token_signed_response_alg ) ; const shouldHaveJwksUri = ! discovery && ( isUserInfoAlgAsymetric || isIdTOkenAlgAsymetric ) ; const isValid = isURL ( JwksUri ) === shouldHaveJwksUri ; return isValid ; } defaultMessage ( ) { return 'JwkURL should not be present with symetric signature algorithms and/or discovery on' ; } }