fix: ensure that number is whole (#2416)

This commit is contained in:
Wyatt Johnson
2019-07-25 00:38:46 +00:00
committed by GitHub
parent b1732f8a00
commit 4f640826de
4 changed files with 10 additions and 5 deletions
@@ -92,7 +92,11 @@ export async function handleLogout(redis: Redis, req: Request, res: Response) {
const { jti, exp }: LogoutToken = validate(LogoutTokenSchema, decoded);
if (jti && exp) {
// Compute the number of seconds that the token will be valid for.
const validFor = exp - now.valueOf() / 1000;
const validFor = Math.round(
DateTime.fromJSDate(now)
.plus({ seconds: -exp })
.toSeconds()
);
if (validFor > 0) {
// Invalidate the token, the expiry is in the future and it needs to be
// revoked.
+3 -2
View File
@@ -3,6 +3,7 @@ import { IncomingMessage } from "http";
import { Redis } from "ioredis";
import Joi from "joi";
import jwt, { SignOptions, VerifyOptions } from "jsonwebtoken";
import { DateTime } from "luxon";
import { Bearer, BearerOptions } from "permit";
import uuid from "uuid/v4";
@@ -352,8 +353,8 @@ export async function revokeJWT(
) {
await redis.setex(
generateJTIRevokedKey(jti),
Math.ceil(validFor),
now.valueOf()
Math.round(validFor),
Math.round(DateTime.fromJSDate(now).toSeconds())
);
}
@@ -86,7 +86,7 @@ export async function generateInviteURL(
jti: uuid.v4(),
iss: tenant.id,
sub: id,
exp: Math.floor(user.expiresAt.valueOf() / 1000),
exp: Math.round(DateTime.fromJSDate(user.expiresAt).toSeconds()),
iat: nowSeconds,
nbf: nowSeconds,
aud: "invite",
+1 -1
View File
@@ -283,7 +283,7 @@ export async function createToken(
issuer: tenant.id,
// Tokens are not valid before the creation date.
notBefore: DateTime.fromJSDate(now).toSeconds(),
notBefore: Math.round(DateTime.fromJSDate(now).toSeconds()),
});
return { ...result, signedToken };