Skip to content

Commit 3842688

Browse files
notanmayKillDozerX2
authored andcommitted
feat: ✨ add static method to instantiate a Verifier class
1 parent 11a6ad6 commit 3842688

1 file changed

Lines changed: 19 additions & 0 deletions

File tree

src/jwt.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,25 @@ export class Verifier<T extends BaseClaims> {
3333
this.disableCaching = disableCaching;
3434
}
3535

36+
/**
37+
* Static method to instantiate a Verifier class
38+
* @param inputToken The input token you get from the request
39+
* @param keysUrlPath The URL path to the public keys
40+
* @param disableCaching Caches keys for 24 hours, defaults to false
41+
* @returns {Verifier} Returns an instance of Verifier class
42+
*/
43+
public static fromToken<T extends BaseClaims>(
44+
inputToken: string,
45+
keysUrlPath: string,
46+
disableCaching = false
47+
): Verifier<T> {
48+
const parsedToken = jwtDecode<T>(this.getCleanedJwt(inputToken));
49+
if (!keysUrlPath.startsWith("/")) {
50+
keysUrlPath = "/" + keysUrlPath;
51+
}
52+
return new Verifier(`${parsedToken.iss}${keysUrlPath}`, disableCaching);
53+
}
54+
3655
private async getPublicKeys(): Promise<Array<PublicKey>> {
3756
if (!this.publicKeys) {
3857
if (!this.disableCaching) {

0 commit comments

Comments
 (0)