From 8fca782f301f8c2324be15d28a965c63d8bea81c Mon Sep 17 00:00:00 2001 From: Miodec Date: Wed, 28 Sep 2022 00:16:45 +0200 Subject: [PATCH] not using cache if requiring fresh token --- backend/src/middlewares/auth.ts | 2 +- backend/src/utils/auth.ts | 9 ++++++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/backend/src/middlewares/auth.ts b/backend/src/middlewares/auth.ts index f1b696946..b1da61912 100644 --- a/backend/src/middlewares/auth.ts +++ b/backend/src/middlewares/auth.ts @@ -144,7 +144,7 @@ async function authenticateWithBearerToken( options: RequestAuthenticationOptions ): Promise { try { - const decodedToken = await verifyIdToken(token); + const decodedToken = await verifyIdToken(token, options.requireFreshToken); if (options.requireFreshToken) { const now = Date.now(); diff --git a/backend/src/utils/auth.ts b/backend/src/utils/auth.ts index 6294c0660..a6222f706 100644 --- a/backend/src/utils/auth.ts +++ b/backend/src/utils/auth.ts @@ -17,7 +17,14 @@ const tokenCache = new LRUCache({ const TOKEN_CACHE_BUFFER = 1000 * 60 * 5; // 5 minutes -export async function verifyIdToken(idToken: string): Promise { +export async function verifyIdToken( + idToken: string, + noCache = false +): Promise { + if (noCache) { + return await admin.auth().verifyIdToken(idToken, true); + } + setTokenCacheLength(tokenCache.size); setTokenCacheSize(tokenCache.calculatedSize ?? 0);