From 02b57eb82ee8c31c47d1e12b73470c0d018ec8db Mon Sep 17 00:00:00 2001 From: Chad Robinson Date: Mon, 3 Nov 2025 06:40:36 -0700 Subject: [PATCH] fix: Add refresh token to refresh-token request response (#24831) * Add refresh token to refresh-token request response This change addresses an issue reported in https://github.com/calcom/cal.com/issues/23939#issuecomment-3443480099 in which a new refresh token is not included in the OAuth2 refresh-token endpoint response. * Address failing type checks --------- Co-authored-by: Pallav <90088723+Pallava-Joshi@users.noreply.github.com> --- .../app/api/auth/oauth/refreshToken/route.ts | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/apps/web/app/api/auth/oauth/refreshToken/route.ts b/apps/web/app/api/auth/oauth/refreshToken/route.ts index f5650aa7b8..ef0baeeee8 100644 --- a/apps/web/app/api/auth/oauth/refreshToken/route.ts +++ b/apps/web/app/api/auth/oauth/refreshToken/route.ts @@ -50,7 +50,7 @@ async function handler(req: NextRequest) { return NextResponse.json({ message: "Unauthorized" }, { status: 401 }); } - const payload: OAuthTokenPayload = { + const payloadAuthToken: OAuthTokenPayload = { userId: decodedRefreshToken.userId, teamId: decodedRefreshToken.teamId, scope: decodedRefreshToken.scope, @@ -58,11 +58,23 @@ async function handler(req: NextRequest) { clientId: client_id, }; - const access_token = jwt.sign(payload, secretKey, { + const payloadRefreshToken: OAuthTokenPayload = { + userId: decodedRefreshToken.userId, + teamId: decodedRefreshToken.teamId, + scope: decodedRefreshToken.scope, + token_type: "Refresh Token", + clientId: client_id, + }; + + const access_token = jwt.sign(payloadAuthToken, secretKey, { expiresIn: 1800, // 30 min }); - return NextResponse.json({ access_token }, { status: 200 }); + const refresh_token = jwt.sign(payloadRefreshToken, secretKey, { + expiresIn: 30 * 24 * 60 * 60, // 30 days + }); + + return NextResponse.json({ access_token, refresh_token }, { status: 200 }); } export const POST = defaultResponderForAppDir(handler);