File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -42,16 +42,33 @@ export class Verifier<T extends BaseClaims> {
4242 * @param disableCaching Caches keys for 24 hours, defaults to false
4343 * @returns {Verifier } Returns an instance of Verifier class
4444 */
45- public static fromToken < T extends BaseClaims > (
45+ public static async fromToken < T extends BaseClaims > (
4646 inputToken : string ,
47+ allowedIssuers ?: string [ ] ,
4748 keysUrlPath = ".well-known/jwks.json" ,
4849 disableCaching = false
49- ) : Verifier < T > {
50+ ) : Promise < { verifier : Verifier < T > ; verifiedToken : T } > {
5051 const parsedToken = jwtDecode < T > ( this . getCleanedJwt ( inputToken ) ) ;
5152 if ( ! keysUrlPath . startsWith ( "/" ) ) {
5253 keysUrlPath = "/" + keysUrlPath ;
5354 }
54- return new Verifier ( `${ parsedToken . iss } ${ keysUrlPath } ` , disableCaching ) ;
55+ if ( ! parsedToken . iss ) {
56+ throw new Error ( "No issuer url found from the token passed" ) ;
57+ }
58+ if ( allowedIssuers && ! allowedIssuers . includes ( parsedToken . iss ) ) {
59+ throw new Error (
60+ "Invalid Token issuer, the issuer from token doesn't match the allowed issuers"
61+ ) ;
62+ }
63+ const verifier = new Verifier < T > (
64+ `${ parsedToken . iss } ${ keysUrlPath } ` ,
65+ disableCaching
66+ ) ;
67+ const verifiedToken = await verifier . getVerifiedToken ( inputToken ) ;
68+ return {
69+ verifier,
70+ verifiedToken,
71+ } ;
5572 }
5673
5774 private async getPublicKeys ( ) : Promise < Array < PublicKey > > {
You can’t perform that action at this time.
0 commit comments