The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
update refresh token creation
Kiran K6383131beb77
diff --git a/apps/web/app/api/integrations/route.ts b/apps/web/app/api/integrations/route.tsindex 143f004b6a..ee1fc05908 100644--- a/apps/web/app/api/integrations/route.ts+++ b/apps/web/app/api/integrations/route.ts@@ -5,15 +5,15 @@ import { NextResponse } from "next/server";// GET /api/integrations - get all active integrationsexport const GET = withWorkspace(async ({ workspace }) => {- const integrations = await prisma.oAuthApp.findMany({+ const integrations = await prisma.integration.findMany({select: {- clientId: true,+ id: true,name: true,slug: true,},where: {verified: true,- authorizedApps: {+ installations: {some: {project: {slug: workspace.slug,diff --git a/apps/web/app/api/oauth/token/refresh-access-token.ts b/apps/web/app/api/oauth/token/refresh-access-token.tsindex b213e17a93..de5cfb4fda 100644--- a/apps/web/app/api/oauth/token/refresh-access-token.ts+++ b/apps/web/app/api/oauth/token/refresh-access-token.ts@@ -43,24 +43,25 @@ export const refreshAccessToken = async (});}- const app = await prisma.oAuthApp.findFirst({+ const oAuthApp = await prisma.oAuthApp.findFirst({where: {clientId,},select: {pkce: true,+ integrationId: true,hashedClientSecret: true,},});- if (!app) {+ if (!oAuthApp) {throw new DubApiError({code: "unauthorized",message: "OAuth app not found for the provided client_id",});}- if (!app.pkce) {+ if (!oAuthApp.pkce) {if (!clientSecret) {throw new DubApiError({code: "unauthorized",@@ -68,7 +69,7 @@ export const refreshAccessToken = async (});}- if (app.hashedClientSecret !== (await hashToken(clientSecret))) {+ if (oAuthApp.hashedClientSecret !== (await hashToken(clientSecret))) {throw new DubApiError({code: "unauthorized",message: "Invalid client_secret",@@ -82,24 +83,12 @@ export const refreshAccessToken = async (},select: {id: true,+ accessTokenId: true,+ installationId: true,expiresAt: true,- authorizedApp: {- select: {- id: true,- userId: true,- clientId: true,- projectId: true,- project: {- select: {- plan: true,- },- },- },- },accessToken: {select: {id: true,- name: true,scopes: true,},},@@ -113,17 +102,52 @@ export const refreshAccessToken = async (});}- if (refreshTokenRecord.authorizedApp.clientId !== clientId) {+ if (refreshTokenRecord.expiresAt < new Date()) {throw new DubApiError({code: "unauthorized",- message: "Client ID mismatch.",+ message: "Refresh token expired.",});}- if (refreshTokenRecord.expiresAt < new Date()) {+ const authorizedApp = await prisma.installedIntegration.findUnique({+ where: {+ id: refreshTokenRecord.installationId,+ },+ select: {+ id: true,+ userId: true,+ projectId: true,+ integration: {+ select: {+ oAuthApp: {+ select: {+ clientId: true,+ },+ },+ },+ },+ project: {+ select: {+ plan: true,+ },+ },+ },+ });++ if (!authorizedApp) {throw new DubApiError({code: "unauthorized",- message: "Refresh token expired.",+ message: "Integration installation not found.",+ });+ }++ const { accessToken } = refreshTokenRecord;+ const { integration } = authorizedApp;++ if (integration.oAuthApp?.clientId !== clientId) {+ throw new DubApiError({+ code: "unauthorized",+ message: "Client ID mismatch.",});}@@ -140,8 +164,6 @@ export const refreshAccessToken = async (Date.now() + OAUTH_CONFIG.ACCESS_TOKEN_LIFETIME * 1000,);- const { accessToken, authorizedApp } = refreshTokenRecord;-await prisma.$transaction([// Delete the old access tokenprisma.restrictedToken.delete({