Skip to content

Commit

Permalink
fix(jwt): Fix ttl in claims (#846)
Browse files Browse the repository at this point in the history
  • Loading branch information
dragonmantank authored Aug 2, 2023
1 parent 8760b0f commit 54fccdc
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
1 change: 1 addition & 0 deletions packages/jwt/__tests__/jwt.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ describe('Token Generator', () => {
const decoded = verify(token, privateKey, { algorithms: ['RS256'] });
expect(decoded.exp).toEqual(decoded.iat + ttl);
expect(decoded.sub).toEqual(subject);
expect(decoded).not.toHaveProperty('ttl');
expect(decoded.acl).toMatchObject(acl);
});
});
7 changes: 6 additions & 1 deletion packages/jwt/lib/jwt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,16 @@ export class JWT implements JWTInterface {
private validateOptions(opts?: GeneratorOptions): Claims {
const now = parseInt((Date.now() / 1000).toString(), 10);

const ttl = opts?.ttl || 900;
if (opts?.ttl) {
delete opts.ttl;
}

const claims: Claims = {
...opts,
jti: opts?.jti || uuidv4(),
iat: opts?.issued_at || now,
exp: now + (opts?.ttl || 900),
exp: now + ttl,
};

if (opts?.subject) {
Expand Down

0 comments on commit 54fccdc

Please sign in to comment.