[{"data":1,"prerenderedAt":7},["ShallowReactive",2],{"docs-partner-connect\u002Fdevice-authorize":3,"docs-tabs-partner-connect\u002Fdevice-authorize":6},{"content":4,"lastmod":5},"\n## Request a device sign-in code\n\n`POST \u002Fv1\u002Fconnect\u002Fdevice\u002Fauthorize`\n\nIssues a confirmation code for signing in from a device without a browser: a TV, a set-top box, a terminal utility — anywhere typing a login and password is awkward. The user confirms the sign-in on a phone or computer, and the device receives access. The flow is defined by RFC 8628.\n\nThe application needs device sign-in enabled: a platform administrator turns it on, and only for verified applications. A self-registered client gets `400 unauthorized_client` — this protects users from confirmation codes displayed by unverified applications.\n\n## Request fields (body)\n\nThe request accepts `application\u002Fjson` and `application\u002Fx-www-form-urlencoded`.\n\n| Field | Type | Required | Description |\n|------|-----|:-----:|----------|\n| `client_id` | string | yes | Identifier of the application for which a platform administrator has enabled device sign-in |\n| `scope` | string | no | Requested permissions, separated by spaces or commas. If omitted, the permissions registered for the client apply |\n| `code_challenge` | string | conditional | SHA-256 hash of `code_verifier` in `base64url` without `=`. Required if PKCE is enabled in the client settings. The platform stores the submitted hash and checks it against `code_verifier` during polling |\n| `code_challenge_method` | string | conditional | `S256`, required together with `code_challenge` |\n| `device_id` | string | no | Persistent identifier of the application installation: up to 128 characters, Latin letters, digits and the characters `.`, `:`, `-`, `_`. The platform adds it to `verification_uri_complete` as the `device_id` parameter to link the steps of one sign-in, even if the link is opened in another browser. A value of any other form is dropped without an error: the response stays `200`, and the link is returned without the parameter. Does not affect issuing a key to a third-party application |\n| `login_source` | string | no | Your sign-in button label for statistics: a lowercase Latin letter followed by lowercase Latin letters, digits and `_`, up to 64 characters in total. Leading and trailing spaces are trimmed. An invalid label does not interrupt the sign-in and does not affect permissions or key issuance |\n| `last_connect_clear` | string | no | Optional window-clear receipt: a JSON string of up to 1024 UTF-8 bytes. Accepted and recorded only for keys of the official Cowork client (`client_id=cowork-desktop`); ignored for other clients. Invalid known values or an oversized receipt cause the entire receipt to be discarded without a connection error. Unknown fields are ignored and never recorded. Omitting the parameter preserves the existing connection flow |\n\n## Examples\n\nThe endpoint authenticates with the application identifier `client_id` in the request body. The `X-Api-Key` and `Authorization` headers are not needed.\n\nKeep `code_verifier` until the exchange at `POST \u002Fv1\u002Fconnect\u002Ftoken`. The curl example uses the RFC 7636 pair with `code_verifier` equal to `dBjftJeZ4CVP-mB92K27uhbUJU1p1r_wW1gFWFOEjXk`. Generate a new random pair for each sign-in, as in the JavaScript example.\n\n### curl — OAuth application\n\n```bash\ncurl -X POST https:\u002F\u002Fvibecode.bitrix24.com\u002Fv1\u002Fconnect\u002Fdevice\u002Fauthorize \\\n  -H \"Content-Type: application\u002Fjson\" \\\n  -d '{\"client_id\":\"YOUR_CLIENT_ID\",\"scope\":\"crm\",\"code_challenge\":\"E9Melhoa2OwvFrEMTJguCHaoeK1t8URWbuGJSstw-cM\",\"code_challenge_method\":\"S256\"}'\n```\n\n### JavaScript — OAuth application\n\n```javascript\nconst base64url = bytes => btoa(String.fromCharCode(...bytes))\n  .replace(\u002F\\+\u002Fg, '-').replace(\u002F\\\u002F\u002Fg, '_').replace(\u002F=+$\u002F, '')\nconst code_verifier = base64url(crypto.getRandomValues(new Uint8Array(32)))\nconst challenge = base64url(new Uint8Array(\n  await crypto.subtle.digest('SHA-256', new TextEncoder().encode(code_verifier)),\n))\n\nconst res = await fetch('https:\u002F\u002Fvibecode.bitrix24.com\u002Fv1\u002Fconnect\u002Fdevice\u002Fauthorize', {\n  method: 'POST',\n  headers: { 'Content-Type': 'application\u002Fjson' },\n  body: JSON.stringify({\n    client_id: 'YOUR_CLIENT_ID',\n    scope: 'crm',\n    code_challenge: challenge,\n    code_challenge_method: 'S256',\n  }),\n})\n\nconst data = await res.json()\n\u002F\u002F data.user_code and data.verification_uri — show to the user\n\u002F\u002F data.device_code — keep on the device, do not display\n```\n\n## Response fields\n\n| Field | Type | Description |\n|------|-----|----------|\n| `device_code` | string | Device secret. Not displayed; sent when polling `POST \u002Fv1\u002Fconnect\u002Ftoken` |\n| `user_code` | string | Code shown to the user together with the URL |\n| `verification_uri` | string | URL where the user enters the code |\n| `verification_uri_complete` | string | The same URL with `user_code` already filled in |\n| `expires_in` | integer | Number of seconds the user has to confirm |\n| `interval` | integer | Polling interval for `POST \u002Fv1\u002Fconnect\u002Ftoken`, in seconds |\n\n## Response example\n\n```json\n{\n  \"device_code\": \"MYQnuWB3H0tR...\",\n  \"user_code\": \"54BV-XT8F\",\n  \"verification_uri\": \"https:\u002F\u002Fvibecode.bitrix24.com\u002Fconnect\u002Fdevice\",\n  \"verification_uri_complete\": \"https:\u002F\u002Fvibecode.bitrix24.com\u002Fconnect\u002Fdevice?user_code=54BV-XT8F\",\n  \"expires_in\": 899,\n  \"interval\": 5\n}\n```\n\n## Error response example\n\n400 — device sign-in is not enabled for this client:\n\n```json\n{\n  \"error\": \"unauthorized_client\",\n  \"error_description\": \"Client is not enabled for the device flow\"\n}\n```\n\n## Errors\n\nRejections come in the RFC 6749 form — `{ error, error_description }`:\n\n| HTTP | `error` | Condition |\n|------|---------|---------|\n| 400 | `invalid_request` | `client_id` is missing. `error_description` — `Missing client_id` |\n| 401 | `invalid_client` | `client_id` is unknown or the client is disabled |\n| 400 | `unauthorized_client` | Device sign-in is not enabled for this client. `error_description` — `Client is not enabled for the device flow` |\n| 400 | `unauthorized_client` | The client is in `COMPANY` mode. `code` and `error_description` — `CONNECT_COMPANY_DEVICE_FLOW_FORBIDDEN` |\n| 400 | `invalid_request` | The client requires PKCE, and `code_challenge` is missing, the method is not `S256`, or the hash is invalid |\n| 400 | `invalid_scope` | An unknown permission or a permission outside the client's registered set is requested |\n\nThe endpoint is rate-limited — 30 requests per minute per caller IP address; `client_id` is not part of the key. On top of that, the platform entry limiter applies, shared across all of `\u002Fv1\u002F`. Exceeding either returns `429` in the common API envelope with a `Retry-After` header. The presence of `X-RateLimit-Limit` shows which one fired.\n\nFull reference of common API errors — [Errors](\u002Fdocs\u002Ferrors).\n\n## Known specifics\n\n**The user opens the URL and confirms.** On the confirmation screen they see the application card, the requested permissions, a Bitrix24 account selector and a phishing warning: confirm only a sign-in you started yourself.\n\n**The device polls `\u002Fv1\u002Fconnect\u002Ftoken`.**\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\": \"urn:ietf:params:oauth:grant-type:device_code\",\n    \"client_id\": \"YOUR_CLIENT_ID\",\n    \"device_code\": \"DEVICE_CODE\",\n    \"code_verifier\": \"CODE_VERIFIER\"\n  }'\n```\n\nUntil the user confirms, the request returns `400` with one of these states:\n\n| `error` | What to do |\n|---------|------------|\n| `authorization_pending` | Wait and keep polling every `interval` seconds |\n| `slow_down` | Polling is more frequent than allowed. Increase the interval by 5 seconds and continue |\n| `access_denied` | The user declined. Stop polling |\n| `access_denied` with `error_description=admin_approval_requested` | The user asked the Bitrix24 account administrator to allow AI for the application. Returned when administrator approval of AI is enabled on the platform. Stop polling, and after the administrator decides, request a new code via `POST \u002Fv1\u002Fconnect\u002Fdevice\u002Fauthorize` |\n| `expired_token` | The code has expired. Request a new one via `POST \u002Fv1\u002Fconnect\u002Fdevice\u002Fauthorize` |\n| `invalid_grant` | The user confirmed the sign-in, but `code_verifier` is missing or does not match `code_challenge` from the code request. Repeat the poll with the correct `code_verifier` |\n\nPolling can also receive `429` — a rate limiter rejection, not an authorization state, and it **comes in two forms** because this route has two limiters. A rejection from the platform entry limiter comes in the RFC 6749 form (`error` equals `slow_down`) and without `X-RateLimit-*` headers. A rejection from the endpoint's own limiter comes in the common API envelope — `{ \"success\": false, \"error\": { \"code\": \"RATE_LIMITED\", \"message\": \"...\" } }` — and carries `X-RateLimit-*` headers. A single branch on `error === \"slow_down\"` is therefore not enough: it misses half of the rejections.\n\nHandle both the same way: wait at least the `Retry-After` value and continue polling without resetting your growing pause. To tell them apart if needed, check for `X-RateLimit-Limit`.\n\nAfter confirmation the same request returns `200` with the key and two permission sets:\n\n```json\n{ \"api_key\": \"vibe_api_...\", \"scopes\": [\"crm\"], \"granted_scopes\": [\"crm\"] }\n```\n\nNote: this object is **narrower** than in the main flow — without the `portal` and `user` blocks.\n\nThe key is returned **once**. A repeated poll with the same `device_code` returns `expired_token`, so save the key immediately.\n\n**What the device must do:**\n\n- **Show a countdown.** The code is valid for 15 minutes. When it expires, show a new one, not a dead screen.\n- **Respect `interval` and react to `slow_down`.** Polling more often than allowed does not speed up issuance; it leads to rejections.\n- **Read `Retry-After` and increase its own pause.** The header value is the minimum pause, not a guarantee that the next request is accepted: all running copies of the application compete for the per-IP limit. Wait at least `Retry-After` and increase your pause with each rejection.\n- **Do not display `device_code`.** Only `user_code` goes on screen.\n\n## See also\n\n- [Exchange a code for an API key](\u002Fdocs\u002Fpartner-connect\u002Ftoken)\n- [Public client: PKCE flow](\u002Fdocs\u002Fpartner-connect\u002Fpkce)\n- [Partner Connect](\u002Fdocs\u002Fpartner-connect)\n","2026-11-23",{},1795415494107]