Files
upstream-mirror e7da97194a
Some checks failed
App Prod-Parity E2E Dispatch / dispatch (push) Failing after 10s
CD Storybook UI / build (push) Failing after 3m25s
CD Storybook UI / dispatch (push) Has been skipped
CD deploy main / website-changed-files (push) Successful in 18m8s
CI Agent Skills / changed-files-check (push) Successful in 18m9s
CI Create App E2E minimal / changed-files-check (push) Successful in 24s
CI Create App / changed-files-check (push) Successful in 26s
CI Docs / changed-files-check (push) Successful in 26s
CI Emails / changed-files-check (push) Successful in 28s
CI Example App Hello World / changed-files-check (push) Successful in 23s
CI Front / changed-files-check (push) Has been skipped
CI Example App Postcard / changed-files-check (push) Successful in 27s
CI UI / changed-files-check (push) Has been skipped
CI Utils Test / changed-files-check (push) Successful in 45s
CI Twenty Apps / discover (push) Successful in 1m3s
CD deploy main / deploy-main (push) Failing after 3s
CI Agent Skills / agent-skills-validate (push) Has been skipped
CI Create App / create-app-test (lint) (push) Has been skipped
CI Emails / emails-test (push) Has been skipped
CI Front / front-task (lingui:compile) (push) Has been skipped
CI Front / front-task (lint) (push) Has been skipped
CI Example App Postcard / example-app-postcard (push) Has been skipped
CI UI / ui-task (lint) (push) Has been skipped
CI UI / ui-task (pack-size) (push) Has been skipped
CI UI / ui-task (size) (push) Has been skipped
CI UI / ui-task (test) (push) Has been skipped
CI UI / ui-task (typecheck) (push) Has been skipped
CI Utils Test / utils-test (push) Has been skipped
CI Twenty Apps / ${{ matrix.app.name }} (push) Has been skipped
CI Emails / ci-emails-status-check (push) Successful in 2s
CI Example App Hello World / ci-example-app-hello-world-status-check (push) Successful in 2s
CI Example App Postcard / ci-example-app-postcard-status-check (push) Successful in 3s
CI UI / ui-sb-test (push) Has been skipped
CI Utils Test / ci-utils-test-status-check (push) Successful in 2s
CI Twenty Apps / ci-twenty-apps-status-check (push) Successful in 2s
CI UI / ci-ui-status-check (push) Successful in 2s
CI Desktop / desktop (push) Failing after 1m8s
Push docs to Crowdin / Push documentation to Crowdin (push) Failing after 55s
Push translations to Crowdin / Extract and upload translations (push) Failing after 5s
Push website translations to Crowdin / Extract and upload website translations (push) Failing after 5s
CI Create App / create-app-test (test) (push) Has been skipped
CI Create App / create-app-test (typecheck) (push) Has been skipped
CI Docs / docs-lint (push) Has been skipped
CI Example App Hello World / example-app-hello-world (push) Has been skipped
CI Front / front-task (lingui:extract) (push) Has been skipped
CI Front / front-task (test) (push) Has been skipped
CI Front / front-task (typecheck) (push) Has been skipped
CI UI / ui-sb-build (push) Failing after 1m32s
CI Twenty Apps / ${{ matrix.app.name }} (${{ matrix.server-source }}) (push) Has been skipped
CI Agent Skills / agent-skills-publish (push) Has been skipped
CI Create App / ci-create-app-status-check (push) Successful in 2s
CI Agent Skills / agent-skills-remote-source (push) Has been skipped
CI Create App E2E minimal / create-app-e2e-minimal (push) Has been cancelled
CI E2E Main / e2e-test (push) Has been cancelled
CI Front / front-sb-build (push) Has been cancelled
CI Front / front-build (push) Has been cancelled
CI Create App E2E minimal / ci-create-app-e2e-minimal-status-check (push) Has been cancelled
CI E2E Main / ci-e2e-main-status-check (push) Has been cancelled
CI E2E Main / notify-main-ci-failure (push) Has been cancelled
CI E2E Main / qa-scout-comment (push) Has been cancelled
CI Front / front-sb-test (push) Has been cancelled
CI Front / front-sb-screenshots (push) Has been cancelled
CI Front / ci-front-status-check (push) Has been cancelled
DPA Sub-Processor Sync / sync-subprocessors (push) Failing after 3s
AI Catalog Sync / sync-catalog (push) Failing after 2s
snapshot of https://github.com/twentyhq/twenty.git (main, 2026-09-17; blobs > 131072B omitted)
2026-09-17 23:28:13 +05:00

190 lines
7.5 KiB
Plaintext

---
title: OAuth
icon: key
description: Fluxul codului de autorizare cu PKCE și acreditări de client pentru acces server-la-server.
---
Twenty implementează OAuth 2.0 cu cod de autorizare + PKCE pentru aplicațiile orientate către utilizatori și acreditări de client pentru acces server-la-server. Clienții sunt înregistrați dinamic prin [RFC 7591](https://datatracker.ietf.org/doc/html/rfc7591) — fără configurare manuală într-un panou de control.
## Când să folosiți OAuth
| Scenariu | Metodă de autentificare |
| ----------------------------------------------------------- | ----------------------------------------------------------------------------------------------- |
| Scripturi interne, automatizare | [Cheie API](/l/ro/developers/extend/api#authentication) |
| Aplicație externă care acționează în numele unui utilizator | **OAuth — Cod de autorizare** |
| Server-la-server, fără context de utilizator | **OAuth — Acreditări de client** |
| Aplicație Twenty cu extensii UI | [Aplicații](/l/ro/developers/extend/apps/getting-started/quick-start) (OAuth este gestionat automat) |
## Înregistrați un client
Twenty acceptă **înregistrarea dinamică a clienților** conform [RFC 7591](https://datatracker.ietf.org/doc/html/rfc7591). Nu este necesară configurare manuală — înregistrați programatic:
```bash
POST /oauth/register
Content-Type: application/json
{
"client_name": "My Integration",
"redirect_uris": ["https://myapp.com/callback"],
"grant_types": ["authorization_code"],
"token_endpoint_auth_method": "client_secret_post"
}
```
**Răspuns:**
```json
{
"client_id": "abc123",
"client_secret": "secret456",
"client_name": "My Integration",
"redirect_uris": ["https://myapp.com/callback"]
}
```
<Warning>
Stocați `client_secret` în siguranță — nu poate fi recuperat ulterior.
</Warning>
## Domenii de aplicare
| Domeniu de aplicare | Acces |
| ------------------- | -------------------------------------------------------------- |
| `api` | Acces complet de citire/scriere la API-urile Core și Metadata |
| `profile` | Citește informațiile de profil ale utilizatorului autentificat |
Solicitați domeniile de aplicare ca un șir separat prin spații: `scope=api profile`
## Fluxul codului de autorizare
Folosiți acest flux când aplicația dvs. acționează în numele unui utilizator Twenty.
### 1. Redirecționați utilizatorul pentru autorizare
```
GET /oauth/authorize?
client_id=YOUR_CLIENT_ID&
response_type=code&
redirect_uri=https://myapp.com/callback&
scope=api&
state=random_state_value&
code_challenge=CHALLENGE&
code_challenge_method=S256
```
| Parametru | Obligatoriu | Descriere |
| ----------------------- | ----------- | --------------------------------------------------------------------- |
| `client_id` | Da | ID-ul clientului înregistrat |
| `response_type` | Da | Trebuie să fie `code` |
| `redirect_uri` | Da | Trebuie să corespundă unei adrese URI de redirecționare înregistrate |
| `scope` | Nu | Domenii de aplicare separate prin spațiu (implicit `api`) |
| `state` | Recomandat | Șir aleatoriu pentru a preveni atacurile CSRF |
| `code_challenge` | Recomandat | Provocare PKCE (hash SHA-256 al verificatorului, codificat base64url) |
| `code_challenge_method` | Recomandat | Trebuie să fie `S256` când se folosește PKCE |
Utilizatorul vede un ecran de consimțământ și aprobă sau refuză accesul.
### 2. Gestionați callback-ul
După autorizare, Twenty redirecționează înapoi către `redirect_uri`-ul dvs.:
```
https://myapp.com/callback?code=AUTH_CODE&state=random_state_value
```
Verificați că `state` corespunde cu ceea ce ați trimis.
### 3. Schimbați codul pe tokenuri
```bash
POST /oauth/token
Content-Type: application/x-www-form-urlencoded
grant_type=authorization_code&
code=AUTH_CODE&
redirect_uri=https://myapp.com/callback&
client_id=YOUR_CLIENT_ID&
client_secret=YOUR_CLIENT_SECRET&
code_verifier=YOUR_PKCE_VERIFIER
```
**Răspuns:**
```json
{
"access_token": "eyJhbG...",
"token_type": "Bearer",
"expires_in": 3600,
"refresh_token": "dGhpcyBpcyBh..."
}
```
### 4. Utilizați tokenul de acces
```bash
GET /rest/companies
Authorization: Bearer ACCESS_TOKEN
```
### 5. Reîmprospătați la expirare
```bash
POST /oauth/token
Content-Type: application/x-www-form-urlencoded
grant_type=refresh_token&
refresh_token=YOUR_REFRESH_TOKEN&
client_id=YOUR_CLIENT_ID&
client_secret=YOUR_CLIENT_SECRET
```
## Fluxul cu acreditări de client
Pentru integrări server-la-server fără interacțiune cu utilizatorul:
```bash
POST /oauth/token
Content-Type: application/x-www-form-urlencoded
grant_type=client_credentials&
client_id=YOUR_CLIENT_ID&
client_secret=YOUR_CLIENT_SECRET&
scope=api
```
Tokenul returnat are acces la nivel de spațiu de lucru, neasociat unui utilizator specific.
## Descoperirea serverului
Twenty publică configurația sa OAuth la un endpoint standard de descoperire:
```
GET /.well-known/oauth-authorization-server
```
Acesta returnează toate endpoint-urile, tipurile de grant acceptate, domeniile de aplicare și capabilitățile — util pentru construirea de clienți OAuth generici.
## Rezumatul endpoint-urilor API
| Endpoint | Scop |
| ----------------------------------------- | -------------------------------------- |
| `/.well-known/oauth-authorization-server` | Descoperirea metadatelor serverului |
| `/oauth/register` | Înregistrare dinamică a clientului |
| `/oauth/authorize` | Autorizarea utilizatorului |
| `/oauth/token` | Schimb și reîmprospătare a tokenurilor |
| Mediu | URL de bază |
| -------------------- | ------------------------ |
| **Cloud** | `https://api.twenty.com` |
| **Găzduire proprie** | `https://{your-domain}` |
## OAuth vs Chei API
| | Chei API | OAuth |
| -------------------------------- | ----------------------------------- | --------------------------------------------- |
| **Configurare** | Generați în Setări | Înregistrați un client, implementați fluxul |
| **Contextul utilizatorului** | Niciunul (nivel de spațiu de lucru) | Permisiunile utilizatorului specific |
| **Cel mai potrivit pentru** | Scripturi, instrumente interne | Aplicații externe, integrări multi-utilizator |
| **Rotirea tokenurilor** | Manual | Automată prin tokenuri de reîmprospătare |
| **Acces pe domenii de aplicare** | Acces API complet | Granular, prin domenii de aplicare |