Skip to content
This repository has been archived by the owner on Oct 31, 2024. It is now read-only.

Commit

Permalink
removing refreshtoken
Browse files Browse the repository at this point in the history
  • Loading branch information
pellicceama committed Oct 16, 2024
1 parent 68ba53a commit 3ce141e
Showing 1 changed file with 2 additions and 42 deletions.
44 changes: 2 additions & 42 deletions packages/engine-backend/router/resourceRouter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,6 @@ export const resourceRouter = trpc.router({
endUserId: zEndUserId.nullish(),
connectorConfigId: zId('ccfg').nullish(),
connectorName: z.string().nullish(),
refreshToken: z.boolean().optional(),
forceRefresh: z.boolean().optional(),
})
.optional(),
Expand Down Expand Up @@ -265,35 +264,6 @@ export const resourceRouter = trpc.router({

resources = updatedResources;

// Remove refresh_token from the response for security reasons if not explicitly requested
if (!input.refreshToken) {
console.log('[listResources] Removing refresh_token from the response');
resources = resources.map(reso => {
// @ts-expect-error
if (reso?.settings?.['oauth']?.credentials?.raw?.refresh_token) {
return {
...reso,
settings: {
...reso.settings,
oauth: {
...reso.settings['oauth'],
credentials: {
// @ts-expect-error
...reso.settings['oauth']?.credentials,
raw: {
// @ts-expect-error
...reso.settings['oauth']?.credentials?.raw,
refresh_token: undefined
}
}
}
}
};
}
return reso;
});
}

return resources as Array<ZRaw['resource']>
}),
getResource: protectedProcedure
Expand All @@ -303,8 +273,7 @@ export const resourceRouter = trpc.router({
})
.input(z.object({
id: zId('reso'),
forceRefresh: z.boolean().optional(),
refreshToken: z.boolean().optional()
forceRefresh: z.boolean().optional()
}))
.output(
// TODO: Should we expand this?
Expand All @@ -323,7 +292,7 @@ export const resourceRouter = trpc.router({
reso.connectorConfigId
)

// Handle forceRefresh and refreshToken
// Handle forceRefresh
// @ts-expect-error
const expiresAt = reso?.settings?.['oauth']?.credentials?.raw?.expires_at

Expand All @@ -335,15 +304,6 @@ export const resourceRouter = trpc.router({
}
reso = resoCheck || reso;
}

if(!input.refreshToken) {
// Remove refresh_token from the response for security reasons
// @ts-expect-error
if (reso?.settings?.['oauth']?.credentials?.raw?.refresh_token) {
// @ts-expect-error
delete reso.settings['oauth'].credentials.raw.refresh_token;
}
}

return {
...reso,
Expand Down

0 comments on commit 3ce141e

Please sign in to comment.