Infisical is the open-source platform for securing secrets, certificates, access, and AI Agents.
TypeScript acmeagentsai-agentscertificate-managementdevsecopsenvironment-variableskubernetesopen-sourcepampkipostgresprivate-caprivileged-access-managementsecret-managementsecret-managersecretssecrets-managementsecuritysecurity-toolsvault
remove unused code
Thiago Araujo da Silva84a068f5b0ac
diff --git a/backend/src/services/oauth-client/oauth-client-fns.test.ts b/backend/src/services/oauth-client/oauth-client-fns.test.tsindex 2e7f2acdd8..9a66283ff2 100644--- a/backend/src/services/oauth-client/oauth-client-fns.test.ts+++ b/backend/src/services/oauth-client/oauth-client-fns.test.ts@@ -3,7 +3,6 @@ import crypto from "node:crypto";import {assertValidOauthClientGrantConfig,computePkceChallenge,- dedupeGrantTypes,isAllowedRedirectUri,isRegisteredRedirectUri,parseBasicAuthHeader@@ -123,18 +122,6 @@ describe("isRegisteredRedirectUri", () => {});});-describe("dedupeGrantTypes", () => {- test("removes duplicates while preserving order", () => {- expect(- dedupeGrantTypes([- OauthGrantType.AuthorizationCode,- OauthGrantType.RefreshToken,- OauthGrantType.AuthorizationCode- ])- ).toEqual([OauthGrantType.AuthorizationCode, OauthGrantType.RefreshToken]);- });-});-describe("assertValidOauthClientGrantConfig", () => {const redirectFlow = {grantTypes: [OauthGrantType.AuthorizationCode, OauthGrantType.RefreshToken],diff --git a/backend/src/services/oauth-client/oauth-client-fns.ts b/backend/src/services/oauth-client/oauth-client-fns.tsindex 68d3281dc0..3fba9f6a58 100644--- a/backend/src/services/oauth-client/oauth-client-fns.ts+++ b/backend/src/services/oauth-client/oauth-client-fns.ts@@ -2,7 +2,7 @@ import crypto from "node:crypto";import { BadRequestError } from "@app/lib/errors";-import { OauthGrantType, REDIRECT_BASED_GRANT_TYPES } from "./oauth-client-types";+import { OauthGrantType } from "./oauth-client-types";export const parseBasicAuthHeader = (authorizationHeader?: string@@ -80,14 +80,6 @@ export const isRegisteredRedirectUri = (registeredUris: string[], redirectUri: s}});-export const dedupeGrantTypes = (grantTypes: OauthGrantType[]) => [...new Set(grantTypes)];--export const hasRedirectBasedGrant = (grantTypes: OauthGrantType[]) =>- grantTypes.some((grantType) => REDIRECT_BASED_GRANT_TYPES.includes(grantType));--export const hasTokenExchangeGrant = (grantTypes: OauthGrantType[]) =>- grantTypes.includes(OauthGrantType.TokenExchange);-type TOauthClientGrantConfig = {grantTypes: OauthGrantType[];resolved: {@@ -107,8 +99,8 @@ export const assertValidOauthClientGrantConfig = ({ grantTypes, resolved, supplithrow new BadRequestError({ message: "At least one grant type must be enabled for an application." });}- const isRedirectBased = hasRedirectBasedGrant(grantTypes);- const isTokenExchange = hasTokenExchangeGrant(grantTypes);+ const isRedirectBased = grantTypes.includes(OauthGrantType.AuthorizationCode);+ const isTokenExchange = grantTypes.includes(OauthGrantType.TokenExchange);if (grantTypes.includes(OauthGrantType.RefreshToken) && !grantTypes.includes(OauthGrantType.AuthorizationCode)) {throw new BadRequestError({diff --git a/backend/src/services/oauth-client/oauth-client-service.ts b/backend/src/services/oauth-client/oauth-client-service.tsindex 815d534d03..49deb1519b 100644--- a/backend/src/services/oauth-client/oauth-client-service.ts+++ b/backend/src/services/oauth-client/oauth-client-service.ts@@ -28,10 +28,7 @@ import { TOauthClientDALFactory } from "./oauth-client-dal";import {assertValidOauthClientGrantConfig,computePkceChallenge,- dedupeGrantTypes,getOauthClientSessionUserAgent,- hasRedirectBasedGrant,- hasTokenExchangeGrant,isRegisteredRedirectUri,PKCE_CODE_VERIFIER_REGEX} from "./oauth-client-fns";@@ -76,6 +73,10 @@ const sanitizeOauthClient = (client: TOauthClients) => {return rest;};+// The generated schema types the column as `string[]`, since it is a plain text[] in Postgres. Every+// value written to it goes through the router's `grantTypesSchema`, so the narrowing holds.+const getGrantTypes = (client: TOauthClients) => client.grantTypes as OauthGrantType[];+const expiresInToSeconds = (expiresIn: string | number) =>typeof expiresIn === "number" ? expiresIn : Math.floor(ms(expiresIn) / 1000);@@ -252,12 +253,12 @@ export const oauthClientServiceFactory = ({client?: TOauthClients;ssoPermissionAction: string;}) => {- const storedGrantTypes = client ? (client.grantTypes as OauthGrantType[]) : [];+ const storedGrantTypes = client ? getGrantTypes(client) : [];- const grantTypes = dedupeGrantTypes(dto.grantTypes ?? storedGrantTypes);- const wasTokenExchangeEnabled = hasTokenExchangeGrant(storedGrantTypes);- const isTokenExchangeEnabled = hasTokenExchangeGrant(grantTypes);- const isRedirectBased = hasRedirectBasedGrant(grantTypes);+ const grantTypes = dto.grantTypes ?? storedGrantTypes;+ const wasTokenExchangeEnabled = storedGrantTypes.includes(OauthGrantType.TokenExchange);+ const isTokenExchangeEnabled = grantTypes.includes(OauthGrantType.TokenExchange);+ const isRedirectBased = grantTypes.includes(OauthGrantType.AuthorizationCode);const redirectUris = dto.redirectUris ?? client?.redirectUris ?? [];const tokenExchangeAudience =@@ -335,9 +336,7 @@ export const oauthClientServiceFactory = ({await checkOauthClientPermission(actor, OrgPermissionActions.Read);const clients = await oauthClientDAL.find({ orgId: actor.orgId });- const filtered = grantType- ? clients.filter((client) => (client.grantTypes as OauthGrantType[]).includes(grantType))- : clients;+ const filtered = grantType ? clients.filter((client) => getGrantTypes(client).includes(grantType)) : clients;return filtered.map(sanitizeOauthClient);};@@ -406,7 +405,7 @@ export const oauthClientServiceFactory = ({const client = await getOrgClientOrThrow(clientDbId, actor.orgId);- const usesTokenExchange = hasTokenExchangeGrant(client.grantTypes as OauthGrantType[]);+ const usesTokenExchange = getGrantTypes(client).includes(OauthGrantType.TokenExchange);if (usesTokenExchange) {await checkSsoConfigPermission(actor, "rotate the secret of an OAuth application that uses token exchange");@@ -428,11 +427,8 @@ export const oauthClientServiceFactory = ({return { client: sanitizeOauthClient(updatedClient), clientSecret };};- const isGrantEnabled = (client: TOauthClients, grantType: OauthGrantType) =>- (client.grantTypes as OauthGrantType[]).includes(grantType);-const assertGrantEnabled = (client: TOauthClients, grantType: OauthGrantType) => {- if (!isGrantEnabled(client, grantType)) {+ if (!getGrantTypes(client).includes(grantType)) {throw new UnauthorizedError({message: `This application is not registered for the '${grantType}' grant type`});@@ -587,8 +583,6 @@ export const oauthClientServiceFactory = ({client: TOauthClients,dto: Extract<TOauthTokenExchangeDTO, { grantType: OauthGrantType.TokenExchange }>) => {- assertGrantEnabled(client, OauthGrantType.TokenExchange);-if (!client.tokenExchangeAudience) {throw new BadRequestError({message:@@ -739,14 +733,13 @@ export const oauthClientServiceFactory = ({const exchangeToken = async (dto: TOauthTokenExchangeDTO) => {const client = await authenticateClient(dto.clientId, dto.clientSecret);+ assertGrantEnabled(client, dto.grantType);if (dto.grantType === OauthGrantType.TokenExchange) {return exchangeSubjectToken(client, dto);}if (dto.grantType === OauthGrantType.AuthorizationCode) {- assertGrantEnabled(client, OauthGrantType.AuthorizationCode);-const codeKey = KeyStorePrefixes.OauthAuthorizationCode(dto.code);const codePayloadRaw = await keyStore.getItem(codeKey);if (!codePayloadRaw) {@@ -807,7 +800,7 @@ export const oauthClientServiceFactory = ({accessTokenExpiresIn);- const refreshToken = isGrantEnabled(client, OauthGrantType.RefreshToken)+ const refreshToken = getGrantTypes(client).includes(OauthGrantType.RefreshToken)? signOauthToken({...sharedClaims,@@ -828,8 +821,6 @@ export const oauthClientServiceFactory = ({};}- assertGrantEnabled(client, OauthGrantType.RefreshToken);-const { decodedToken, tokenVersion, isGraceHit } = await tokenService.validateRefreshToken(dto.refreshToken, {allowOauthClientToken: true});diff --git a/backend/src/services/oauth-client/oauth-client-types.ts b/backend/src/services/oauth-client/oauth-client-types.tsindex ed3d77c2fd..5f43320f74 100644--- a/backend/src/services/oauth-client/oauth-client-types.ts+++ b/backend/src/services/oauth-client/oauth-client-types.ts@@ -10,9 +10,6 @@ export enum OauthGrantType {TokenExchange = "urn:ietf:params:oauth:grant-type:token-exchange"}-// Grants that mint tokens through a browser redirect, so they need registered redirect URIs.-export const REDIRECT_BASED_GRANT_TYPES: readonly OauthGrantType[] = [OauthGrantType.AuthorizationCode];-// Applied as the create default so an API caller written before this feature, which sends no// `grantTypes`, keeps registering redirect-flow applications.export const DEFAULT_OAUTH_GRANT_TYPES: readonly OauthGrantType[] = [