From fe9012e73f3019dd7167cb00826b3a7a678f2766 Mon Sep 17 00:00:00 2001 From: Nicolas Ayral Seydoux Date: Tue, 14 Jan 2025 11:06:22 +0100 Subject: [PATCH] Fix expiration date unit --- packages/browser/src/login/oidc/ClientRegistrar.ts | 4 +++- packages/node/src/login/oidc/ClientRegistrar.ts | 3 ++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/packages/browser/src/login/oidc/ClientRegistrar.ts b/packages/browser/src/login/oidc/ClientRegistrar.ts index 3daae63fe..047232d24 100644 --- a/packages/browser/src/login/oidc/ClientRegistrar.ts +++ b/packages/browser/src/login/oidc/ClientRegistrar.ts @@ -75,8 +75,9 @@ export default class ClientRegistrar implements IClientRegistrar { const expirationDate = expiresAt !== undefined ? Number.parseInt(expiresAt, 10) : -1; // Expiration is only applicable to confidential clients. + // Note that Date.now() is in milliseconds, and expirationDate in seconds. const expired = - storedClientSecret !== undefined && Date.now() > expirationDate; + storedClientSecret !== undefined && Math.floor(Date.now() / 1000) > expirationDate; if (storedClientId && isKnownClientType(storedClientType) && !expired) { return storedClientSecret !== undefined ? { @@ -97,6 +98,7 @@ export default class ClientRegistrar implements IClientRegistrar { } try { + console.log(`Registering a new client`); const registeredClient = await registerClient(options, issuerConfig); // Save info const infoToSave: Record = { diff --git a/packages/node/src/login/oidc/ClientRegistrar.ts b/packages/node/src/login/oidc/ClientRegistrar.ts index 3ba709aa1..fc2a41c6a 100644 --- a/packages/node/src/login/oidc/ClientRegistrar.ts +++ b/packages/node/src/login/oidc/ClientRegistrar.ts @@ -110,7 +110,8 @@ export default class ClientRegistrar implements IClientRegistrar { const expired = storedClientSecret !== undefined && storedClientType === "dynamic" && - Date.now() > expirationDate; + // Note that Date.now() is in milliseconds, and expirationDate in seconds. + Math.floor(Date.now() / 1000) > expirationDate; if ( storedClientId !== undefined && isKnownClientType(storedClientType) &&