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.6 KiB
Plaintext
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
---
title: OAuth
icon: key
description: Flux de code d’autorisation avec PKCE et identifiants client pour l’accès serveur à serveur.
---
Twenty implémente OAuth 2.0 avec code d’autorisation + PKCE pour les applications destinées aux utilisateurs et des identifiants client pour l’accès serveur à serveur. Les clients sont enregistrés dynamiquement via [RFC 7591](https://datatracker.ietf.org/doc/html/rfc7591) — aucune configuration manuelle dans un tableau de bord.
## Quand utiliser OAuth
| Scénario | Méthode d’authentification |
| -------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------- |
| Scripts internes, automatisation | [Clé API](/l/fr/developers/extend/api#authentication) |
| Application externe agissant au nom d’un utilisateur | **OAuth — Code d’autorisation** |
| Serveur à serveur, aucun contexte utilisateur | **OAuth — Identifiants client** |
| Application Twenty avec des extensions d’interface utilisateur | [Applications](/l/fr/developers/extend/apps/getting-started/quick-start) (OAuth est géré automatiquement) |
## Enregistrer un client
Twenty prend en charge **l’enregistrement dynamique de clients** conformément à [RFC 7591](https://datatracker.ietf.org/doc/html/rfc7591). Aucune configuration manuelle requise — enregistrez le client par programmation :
```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éponse:**
```json
{
"client_id": "abc123",
"client_secret": "secret456",
"client_name": "My Integration",
"redirect_uris": ["https://myapp.com/callback"]
}
```
<Warning>
Stockez le `client_secret` en toute sécurité — il ne peut pas être récupéré ultérieurement.
</Warning>
## Périmètres
| Périmètre | Accès |
| --------- | ------------------------------------------------------------ |
| `api` | Accès complet en lecture/écriture aux API Core et Metadata |
| `profil` | Lire les informations de profil de l’utilisateur authentifié |
Demandez les périmètres sous forme de chaîne séparée par des espaces : `scope=api profile`
## Flux de code d’autorisation
Utilisez ce flux lorsque votre application agit au nom d’un utilisateur Twenty.
### 1. Rediriger l’utilisateur vers l’écran d’autorisation
```
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
```
| Paramètre | Obligatoire | Description |
| ----------------------- | ----------- | ---------------------------------------------------------------- |
| `client_id` | Oui | Votre identifiant client enregistré |
| `response_type` | Oui | Doit être `code` |
| `redirect_uri` | Oui | Doit correspondre à une URI de redirection enregistrée |
| `scope` | Non | Périmètres séparés par des espaces (par défaut : `api`) |
| `état` | Recommandé | Chaîne aléatoire pour empêcher les attaques CSRF |
| `code_challenge` | Recommandé | Défi PKCE (hachage SHA-256 du vérificateur, encodé en base64url) |
| `code_challenge_method` | Recommandé | Doit être `S256` lors de l’utilisation de PKCE |
L’utilisateur voit un écran de consentement et approuve ou refuse l’accès.
### 2. Gérer la redirection
Après l’autorisation, Twenty redirige vers votre `redirect_uri` :
```
https://myapp.com/callback?code=AUTH_CODE&state=random_state_value
```
Vérifiez que `state` correspond à ce que vous avez envoyé.
### 3. Échanger le code contre des jetons
```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éponse:**
```json
{
"access_token": "eyJhbG...",
"token_type": "Bearer",
"expires_in": 3600,
"refresh_token": "dGhpcyBpcyBh..."
}
```
### 4. Utiliser le jeton d’accès
```bash
GET /rest/companies
Authorization: Bearer ACCESS_TOKEN
```
### 5. Actualiser à l’expiration
```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
```
## Flux des identifiants client
Pour les intégrations serveur à serveur sans interaction utilisateur :
```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
```
Le jeton renvoyé dispose d’un accès au niveau de l’espace de travail, non lié à un utilisateur spécifique.
## Découverte du serveur
Twenty publie sa configuration OAuth à un point de découverte standard :
```
GET /.well-known/oauth-authorization-server
```
Cela renvoie tous les points de terminaison, les types d’octroi pris en charge, les périmètres et les capacités — utile pour créer des clients OAuth génériques.
## Résumé des points de terminaison API
| Point de terminaison | Objectif |
| ----------------------------------------- | ------------------------------------- |
| `/.well-known/oauth-authorization-server` | Découverte des métadonnées du serveur |
| `/oauth/register` | Enregistrement dynamique de clients |
| `/oauth/authorize` | Autorisation de l’utilisateur |
| `/oauth/token` | Échange et actualisation de jetons |
| Environnement | URL de base |
| ---------------- | ------------------------ |
| **Cloud** | `https://api.twenty.com` |
| **Auto-hébergé** | `https://{your-domain}` |
## OAuth vs clés API
| | Clés API | OAuth |
| ------------------------ | ---------------------------------------- | ------------------------------------------------------ |
| **Installation** | Générer dans Paramètres | Enregistrer un client, implémenter le flux |
| **Contexte utilisateur** | Aucun (au niveau de l’espace de travail) | Autorisations d’un utilisateur spécifique |
| **Idéal pour** | Scripts, outils internes | Applications externes, intégrations multi-utilisateurs |
| **Rotation des jetons** | Manuel | Automatique via des jetons d’actualisation |
| **Accès par périmètre** | Accès complet à l’API | Granulaire via des périmètres |