Skip to content

Commit

Permalink
feat: add refresh token to OAuthConfig update
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
schettn committed Jun 20, 2024
1 parent c34d414 commit 996515e
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion src/repository/models/OAuthConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 996515e

Please sign in to comment.