[{"data":1,"prerenderedAt":7},["ShallowReactive",2],{"docs-partner-connect\u002Fpkce":3,"docs-tabs-partner-connect\u002Fpkce":6},{"content":4,"lastmod":5},"# Public client: the PKCE flow\n\nThe main flow — [`GET \u002Fv1\u002Fconnect\u002Fauthorize`](\u002Fdocs\u002Fpartner-connect\u002Fauthorize) and [`POST \u002Fv1\u002Fconnect\u002Ftoken`](\u002Fdocs\u002Fpartner-connect\u002Ftoken) — is described for a confidential client: one that has a server and a `client_secret`. If there is no server and nowhere to hide a secret (a mobile application, a desktop program, a single-page web application), register a public client. It is not issued a secret: the PKCE mechanism proves its authenticity instead.\n\nThe PKCE flow differs from the main flow in three steps. Everything else is the same.\n\n## Step 1. Create a pair of strings\n\nEach time the flow runs, the application creates a random string, `code_verifier`, and its SHA-256 hash, `code_challenge`, encoded as base64url without `=` padding.\n\n```javascript\nimport crypto from 'node:crypto'\n\nconst b64url = (buf) => buf.toString('base64url')\nconst verifier  = b64url(crypto.randomBytes(32))\nconst challenge = b64url(crypto.createHash('sha256').update(verifier).digest())\n```\n\nKeep `verifier` until the flow ends. `challenge` goes into the first request.\n\n## Step 2. Pass the hash to `\u002Fv1\u002Fconnect\u002Fauthorize`\n\n| Parameter | Value |\n|----------|----------|\n| `code_challenge` | The hash from step 1 |\n| `code_challenge_method` | Always `S256`. Other values are rejected |\n\nFor a public client both parameters are **required**: without them the flow ends in a redirect with `error=invalid_request`.\n\n## Step 3. Pass `code_verifier` to `\u002Fv1\u002Fconnect\u002Ftoken`\n\nThe exchange takes `code_verifier` instead of `client_secret`:\n\n```bash\ncurl -X POST https:\u002F\u002Fvibecode.bitrix24.com\u002Fv1\u002Fconnect\u002Ftoken \\\n  -H \"Content-Type: application\u002Fjson\" \\\n  -d '{\n    \"grant_type\": \"authorization_code\",\n    \"client_id\": \"YOUR_CLIENT_ID\",\n    \"code\": \"RECEIVED_CODE\",\n    \"redirect_uri\": \"http:\u002F\u002F127.0.0.1:9999\u002Fcallback\",\n    \"code_verifier\": \"CODE_VERIFIER\"\n  }'\n```\n\nThe response is the same as for a confidential client — the fields are described on the [`POST \u002Fv1\u002Fconnect\u002Ftoken`](\u002Fdocs\u002Fpartner-connect\u002Ftoken#response-fields) page.\n\n**A public client must not send `client_secret`** — the platform responds with `400 invalid_client`. A secret shipped inside a distributed application is not a secret, and the flow is designed so that such a secret cannot be used.\n\n## Returning to localhost\n\nA program without a website of its own has no public address to receive the code at. For such cases a redirect back to itself is allowed: register a `redirect_uri` such as `http:\u002F\u002F127.0.0.1:9999\u002Fcallback`, start a listener on that port for the duration of the flow, and close it as soon as the code arrives.\n\nThe addresses `127.0.0.1`, `localhost` and `[::1]` are accepted, with either the `http` or `https` scheme. Every other address must be `https`. The scheme and the path are always matched, while the port and the localhost address itself are matched depending on the client type:\n\n| Client type | How a localhost address is matched |\n|---|---|\n| Public | The port is **not taken into account**: if it is in use, the application may listen on any other one without registering the address again. The addresses `127.0.0.1`, `localhost` and `[::1]` are interchangeable: a registered `http:\u002F\u002F127.0.0.1\u002Fcallback` also accepts `http:\u002F\u002Flocalhost:5123\u002Fcallback` |\n| Confidential | The whole address is matched, port included. This is how a server application is debugged on your own computer: register the address with the port your server listens on, for example `http:\u002F\u002Flocalhost:3030\u002Fcallback` |\n\nThe name `localhost` can point somewhere other than this computer if it is overridden in the network settings, so `127.0.0.1` is more reliable.\n\n## See also\n\n- [Start user authorization](\u002Fdocs\u002Fpartner-connect\u002Fauthorize)\n- [Exchange the code for an API key](\u002Fdocs\u002Fpartner-connect\u002Ftoken)\n- [Client types](\u002Fdocs\u002Fpartner-connect#client-types)\n- [Partner Connect](\u002Fdocs\u002Fpartner-connect)\n","2026-11-19",{},1795415494652]