From c964163cc5ad10c3b6062b73f2fd21d5bd420b70 Mon Sep 17 00:00:00 2001 From: Tom Moor Date: Sun, 4 Sep 2022 12:56:00 +0200 Subject: [PATCH] fix: Handle GitLab can be configured for tokens to not expire. (#4051) closes #4040 --- server/models/UserAuthentication.ts | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/server/models/UserAuthentication.ts b/server/models/UserAuthentication.ts index 37dde8322..ee3433b4f 100644 --- a/server/models/UserAuthentication.ts +++ b/server/models/UserAuthentication.ts @@ -142,7 +142,13 @@ class UserAuthentication extends IdModel { authenticationProvider: AuthenticationProvider, options: SaveOptions ): Promise { - if (this.expiresAt > addMinutes(Date.now(), 5) || !this.refreshToken) { + if ( + this.expiresAt > addMinutes(Date.now(), 5) || + !this.refreshToken || + // Some providers send no expiry depending on setup, in this case we can't + // refresh and assume the session is valid until logged out. + !this.expiresAt + ) { return false; } @@ -162,7 +168,7 @@ class UserAuthentication extends IdModel { } this.accessToken = response.accessToken; this.expiresAt = response.expiresAt; - this.save(options); + await this.save(options); } Logger.info("utils", "Successfully refreshed expired access token", {