Docs

Rotate a client secret

POST
/applications/{application_id}/client_secret/rotate

Replaces the secret of one confidential client of an application and returns the new secret once. Name the client by its slug in client; the application's definition.clients lists them, as getApplication (GET /applications/{application_id}) returns it.

previous_secrets says what becomes of the secrets the client holds now:

  • revoke ends them at once. Use it for a secret that leaked: from this call on, only the new secret authenticates the client. Every app that still sends an old one fails to sign its users in until it has the new secret, so update it right after the call.
  • keep_one_day keeps them working for 24 hours beside the new secret. Use it to replace a secret on a schedule: update every app that sends the secret, and the old one ends by itself. A later call with revoke ends it sooner.

The answer's previous_secrets_end_at says when the old secrets stop working. The server stores only the new secret's hash, so no later read returns it: store it where you keep secrets before you close the answer. Each call replaces the secret again, so a retry after a lost answer issues another new secret; the one the lost answer held stops working as previous_secrets says.

The call records an application.client_secret.rotated event, which names who rotated the secret, the client, and when its previous secrets end.

An application a release declares keeps its client's secret in a variable, so the call refuses it with app.declared: set a new value with setVariables (PATCH /variables) and deploy. A public client holds no secret and is refused with app.invalid. The application is looked up in the project in project_id.

Authorization

oauth2 application.write
headerAuthorizationBearer <token>

Scope: application.write

Path Parameters

application_id*string

The application ID: the id that publishApplication (POST /applications) returns.

Query Parameters

project_id*string

The project ID: the id that createProject (POST /projects) returns. zitadel setup prints it as "Project id" in its summary and as project_id with --json, and writes it to .env.local as ZITADEL_PROJECT_ID.

Match^[a-zA-Z0-9_-]+$

Request Body

application/json
  1. body

The client whose secret to replace, and what becomes of the secrets it holds now.

client*string

The slug of the client whose secret to replace, as the application's definition.clients[].slug names it.

previous_secrets*string

What becomes of the secrets the client holds now. revoke ends them at once: use it for a secret that leaked. Every app that still sends one fails to authenticate the client until it has the new secret. keep_one_day keeps them working for 24 hours beside the new one, so each app can move to the new secret before the old one ends.

Value in"revoke""keep_one_day"

Response Body

The client's new secret, shown only in this answer, and when its previous secrets stop working.

application/json
  1. response

The client's new secret, and when the secrets it held before stop working.

client_secret*

A client secret the server generated, returned once.

previous_secrets_end_at*string

When the last of the secrets the client held before stops working: the time of this call for revoke, 24 hours after the new secret was stored for keep_one_day. A secret an earlier keep_one_day kept still ends when that call said, which can be sooner.

Formatdate-time
import { createZitadelApi, ZitadelClient } from "@zitadel/api/client";const api = createZitadelApi(  new ZitadelClient({    baseUrl: process.env.ZITADEL_URL ?? "http://localhost:8080",    token: process.env.ZITADEL_PROJECT_SECRET!, // server-side only  }),);const result = await api.rotateApplicationClientSecret(  "app_01KWH3B72K7M7F0N9WD3P2E4YM",  { client: "web", previous_secrets: "keep_one_day" },  { project_id: "proj_01KWH1P4MYS7F0N9WD3P2E4YM5" },);
Example Response
{  "client_secret": {    "client": "web",    "client_id": "client_01KWH3B72K7M7F0N9WD3P2E4YP",    "secret": "sk_client_9Rt4nWq2vX7kL3mB8zY5hJ6fD1sA0eC4"  },  "previous_secrets_end_at": "2026-12-03T09:14:00Z"}

Was this helpful?