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
feat(api): added revoke access token endpoint
=e3184a5f4083
diff --git a/backend/src/lib/api-docs/constants.ts b/backend/src/lib/api-docs/constants.tsindex 483f8e54c5..f9a5ef312d 100644--- a/backend/src/lib/api-docs/constants.ts+++ b/backend/src/lib/api-docs/constants.ts@@ -89,6 +89,9 @@ export const UNIVERSAL_AUTH = {},RENEW_ACCESS_TOKEN: {accessToken: "The access token to renew."+ },+ REVOKE_ACCESS_TOKEN: {+ accessToken: "The access token to revoke."}} as const;diff --git a/backend/src/server/routes/v1/identity-access-token-router.ts b/backend/src/server/routes/v1/identity-access-token-router.tsindex 387c54c134..7ed62e6798 100644--- a/backend/src/server/routes/v1/identity-access-token-router.ts+++ b/backend/src/server/routes/v1/identity-access-token-router.ts@@ -36,4 +36,29 @@ export const registerIdentityAccessTokenRouter = async (server: FastifyZodProvid};}});++ server.route({+ url: "/token/revoke",+ method: "POST",+ config: {+ rateLimit: writeLimit+ },+ schema: {+ description: "Revoke access token",+ body: z.object({+ accessToken: z.string().trim().describe(UNIVERSAL_AUTH.REVOKE_ACCESS_TOKEN.accessToken)+ }),+ response: {+ 200: z.object({+ message: z.string()+ })+ }+ },+ handler: async (req) => {+ await server.services.identityAccessToken.revokeAccessToken(req.body.accessToken);+ return {+ message: "Successfully revoked access token"+ };+ }+ });};diff --git a/backend/src/services/identity-access-token/identity-access-token-service.ts b/backend/src/services/identity-access-token/identity-access-token-service.tsindex 4b53c81742..898d0bc623 100644--- a/backend/src/services/identity-access-token/identity-access-token-service.ts+++ b/backend/src/services/identity-access-token/identity-access-token-service.ts@@ -106,6 +106,24 @@ export const identityAccessTokenServiceFactory = ({return { accessToken, identityAccessToken: updatedIdentityAccessToken };};+ const revokeAccessToken = async (accessToken: string) => {+ const appCfg = getConfig();++ const decodedToken = jwt.verify(accessToken, appCfg.AUTH_SECRET) as JwtPayload & {+ identityAccessTokenId: string;+ };+ if (decodedToken.authTokenType !== AuthTokenType.IDENTITY_ACCESS_TOKEN) throw new UnauthorizedError();++ const identityAccessToken = await identityAccessTokenDAL.findOne({+ [`${TableName.IdentityAccessToken}.id` as "id"]: decodedToken.identityAccessTokenId,+ isAccessTokenRevoked: false+ });+ if (!identityAccessToken) throw new UnauthorizedError();++ const revokedToken = await identityAccessTokenDAL.deleteById(identityAccessToken.id);+ return { revokedToken };+ };+const fnValidateIdentityAccessToken = async (token: TIdentityAccessTokenJwtPayload, ipAddress?: string) => {const identityAccessToken = await identityAccessTokenDAL.findOne({[`${TableName.IdentityAccessToken}.id` as "id"]: token.identityAccessTokenId,@@ -132,5 +150,5 @@ export const identityAccessTokenServiceFactory = ({return { ...identityAccessToken, orgId: identityOrgMembership.orgId };};- return { renewAccessToken, fnValidateIdentityAccessToken };+ return { renewAccessToken, revokeAccessToken, fnValidateIdentityAccessToken };};