From c543160aecc4de7417ff64d99144377a6d91ebb7 Mon Sep 17 00:00:00 2001 From: Nico Schett Date: Thu, 20 Jun 2024 11:01:28 +0200 Subject: [PATCH] feat: add refresh token to OAuthConfig update This commit adds the refresh token to the update method in the OAuthConfig class. It also includes a check for the presence of the refresh token and logs a warning if it is not returned during token refresh. Note: This message follows the established commit message conventions in the repository. --- src/repository/models/OAuthConfig.ts | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/repository/models/OAuthConfig.ts b/src/repository/models/OAuthConfig.ts index 52c8928..6a61959 100644 --- a/src/repository/models/OAuthConfig.ts +++ b/src/repository/models/OAuthConfig.ts @@ -4,7 +4,7 @@ import * as oidcGoogle from "../../services/oauth/google"; import * as oidcAzure from "../../services/oauth/azure"; import { client } from "../client"; import { OAuthConfigRepository } from "../.generated"; -import { ServiceError } from "@cronitio/pylon"; +import { ServiceError, logger } from "@cronitio/pylon"; import { PYLON_URL } from "src/config"; import { Organization } from "./Organization"; @@ -44,10 +44,17 @@ export class OAuthConfig extends OAuthConfigRepository { const tokenSet = await client.refresh(this.$refreshToken); + if (!tokenSet.refresh_token) { + logger.warn("Refresh token not returned during token refresh", { + tokenSet, + }); + } + await OAuthConfig.objects.update( { accessToken: tokenSet.access_token, accessTokenExpiresAt: new Date(tokenSet.expires_at! * 1000), + refreshToken: tokenSet.refresh_token, }, { id: this.id, @@ -79,10 +86,17 @@ export class OAuthConfig extends OAuthConfigRepository { const tokenSet = await client.refresh(this.$refreshToken); + if (!tokenSet.refresh_token) { + logger.warn("Refresh token not returned during token refresh", { + tokenSet, + }); + } + await OAuthConfig.objects.update( { accessToken: tokenSet.access_token, accessTokenExpiresAt: new Date(tokenSet.expires_at! * 1000), + refreshToken: tokenSet.refresh_token, }, { id: this.id,