Skip to content

Commit

Permalink
fix(asap): reply with 403 for failure to fetch secret (#159)
Browse files Browse the repository at this point in the history
  • Loading branch information
aaronkvanmeerten authored Oct 30, 2024
1 parent 47fcfc9 commit f86427d
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/asap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import got from 'got';
import sha256 from 'sha256';
import NodeCache from 'node-cache';
import { Request } from 'express';
import { UnauthorizedError } from 'express-jwt';
import jwt from 'jsonwebtoken';

export class ASAPPubKeyFetcher {
Expand All @@ -17,7 +18,7 @@ export class ASAPPubKeyFetcher {

async secretCallback(req: Request, token: jwt.Jwt): Promise<jwt.Secret> {
if (!token.header.kid) {
throw new Error('kid is required in header');
throw new UnauthorizedError('credentials_bad_format', new Error('kid is required in the header'));
}

let pubKey = <jwt.Secret>this.cache.get(token.header.kid);
Expand All @@ -39,7 +40,7 @@ export class ASAPPubKeyFetcher {
kid: token.header.kid,
err,
});
throw err;
throw new UnauthorizedError('invalid_token', err);
}
}
}
Expand Down

0 comments on commit f86427d

Please sign in to comment.