diff --git a/plugins/auth-backend/src/identity/DatabaseKeyStore.test.ts b/plugins/auth-backend/src/identity/DatabaseKeyStore.test.ts index 3c61e20c1c..8896a0d158 100644 --- a/plugins/auth-backend/src/identity/DatabaseKeyStore.test.ts +++ b/plugins/auth-backend/src/identity/DatabaseKeyStore.test.ts @@ -16,7 +16,7 @@ import Knex from 'knex'; import { DatabaseKeyStore } from './DatabaseKeyStore'; -import { DateTime } from 'luxon' +import { DateTime } from 'luxon'; function createDB() { const knex = Knex({ @@ -52,7 +52,9 @@ describe('DatabaseKeyStore', () => { const { items } = await store.listKeys(); expect(items).toEqual([{ createdAt: expect.anything(), key }]); expect( - Math.abs(DateTime.fromJSDate(items[0].createdAt).diffNow('seconds').seconds), + Math.abs( + DateTime.fromJSDate(items[0].createdAt).diffNow('seconds').seconds, + ), ).toBeLessThan(10); }); diff --git a/plugins/auth-backend/src/identity/DatabaseKeyStore.ts b/plugins/auth-backend/src/identity/DatabaseKeyStore.ts index 2c3cf41259..6183c2ed66 100644 --- a/plugins/auth-backend/src/identity/DatabaseKeyStore.ts +++ b/plugins/auth-backend/src/identity/DatabaseKeyStore.ts @@ -77,7 +77,10 @@ export class DatabaseKeyStore implements KeyStore { } const parseDate = (date: string | Date) => { - const parsedDate = typeof date === 'string' ? DateTime.fromSQL(date, {locale: 'UTC'}) : DateTime.fromJSDate(date) + const parsedDate = + typeof date === 'string' + ? DateTime.fromSQL(date, { locale: 'UTC' }) + : DateTime.fromJSDate(date); if (!parsedDate.isValid) { throw new Error( @@ -85,5 +88,5 @@ const parseDate = (date: string | Date) => { ); } - return parsedDate.toJSDate() -} + return parsedDate.toJSDate(); +}; diff --git a/plugins/auth-backend/src/identity/MemoryKeyStore.ts b/plugins/auth-backend/src/identity/MemoryKeyStore.ts index efb81cd264..3dc1d777c9 100644 --- a/plugins/auth-backend/src/identity/MemoryKeyStore.ts +++ b/plugins/auth-backend/src/identity/MemoryKeyStore.ts @@ -18,10 +18,7 @@ import { KeyStore, AnyJWK, StoredKey } from './types'; import { DateTime } from 'luxon'; export class MemoryKeyStore implements KeyStore { - private readonly keys = new Map< - string, - { createdAt: Date; key: string } - >(); + private readonly keys = new Map(); async addKey(key: AnyJWK): Promise { this.keys.set(key.kid, { diff --git a/plugins/auth-backend/src/identity/TokenFactory.ts b/plugins/auth-backend/src/identity/TokenFactory.ts index 4169484191..1c6192d5c5 100644 --- a/plugins/auth-backend/src/identity/TokenFactory.ts +++ b/plugins/auth-backend/src/identity/TokenFactory.ts @@ -119,16 +119,21 @@ export class TokenFactory implements TokenIssuer { private async getKey(): Promise { // Make sure that we only generate one key at a time if (this.privateKeyPromise) { - if (this.keyExpiry && DateTime.fromJSDate(this.keyExpiry) > DateTime.local()) { + if ( + this.keyExpiry && + DateTime.fromJSDate(this.keyExpiry) > DateTime.local() + ) { return this.privateKeyPromise; } this.logger.info(`Signing key has expired, generating new key`); delete this.privateKeyPromise; } - this.keyExpiry = DateTime.utc().plus({ - seconds: this.keyDurationSeconds, - }).toJSDate(); + this.keyExpiry = DateTime.utc() + .plus({ + seconds: this.keyDurationSeconds, + }) + .toJSDate(); const promise = (async () => { // This generates a new signing key to be used to sign tokens until the next key rotation const key = await JWK.generate('EC', 'P-256', {