Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/decorators/jwt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,16 @@ export class JwtDecorator {
issuer: string;
audience: string;
}): Promise<string> => {
const timestamp = new Date();

return new SignJWT(payload)
.setProtectedHeader({ alg: 'RS256', kid: JWT_KEY_ID })
.setSubject(subject)
.setIssuer(issuer)
.setAudience(audience)
.setExpirationTime('1h')
.setIssuedAt()
.setNotBefore(timestamp)
.setIssuedAt(timestamp)
.sign(privateKey);
};

Expand Down
18 changes: 18 additions & 0 deletions test/decorators/jwt.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,24 @@ describe('decorators > jwt', () => {
expect(diff).toBeGreaterThan(3500); // ~58 minutes
expect(diff).toBeLessThan(3700); // ~61 minutes
});

it('should set nbf equal to iat', async () => {
const token = await jwt.signOpenIdJwt({
payload: {},
subject: 'user-123',
issuer: 'test',
audience: 'test'
});

const result = await jwt.verify(token);

if (!result.valid) {
expect(true).toBeFalsy();
return;
}

expect(result.payload.nbf).toBe(result.payload.iat);
});
});

describe('signOAuthJwt', () => {
Expand Down
Loading