Authentification
L'API téo utilise OAuth 2.0 pour sécuriser les accès. Cette page explique comment obtenir et utiliser un token d'authentification.
Fonctionnement
Vos identifiants
Après en avoir fait la demande au support client, vous recevrez :
| Identifiant | Description |
|---|---|
CLIENT_ID | Identifiant unique de votre application |
CLIENT_SECRET | Clé secrète (à ne jamais exposer publiquement) |
TEO_ID | Identifiant de l'instance téo à laquelle accéder |
Sécurité
Ne partagez jamais votre CLIENT_SECRET. Ne le commitez pas dans votre code source et ne l'exposez pas côté client (navigateur).
Obtenir un Access Token
Requête
POST https://auth.teoapp.fr/oauth2/token
Content-Type: application/x-www-form-urlencoded
Authorization: Basic {credentials_base64}
grant_type=client_credentials&scope=target-entity:{TEO_ID}
Le header Authorization contient vos identifiants encodés en Base64 au format CLIENT_ID:CLIENT_SECRET.
Exemples
- curl
- JavaScript
- PHP
- Python
# Encoder les credentials
CREDENTIALS=$(echo -n "votre_client_id:votre_client_secret" | base64)
# Obtenir le token
curl -X POST https://auth.teoapp.fr/oauth2/token \
-H "Content-Type: application/x-www-form-urlencoded" \
-H "Authorization: Basic $CREDENTIALS" \
-d "grant_type=client_credentials&scope=target-entity:votre_teo_id"
const clientId = 'votre_client_id';
const clientSecret = 'votre_client_secret';
const teoId = 'votre_teo_id';
const credentials = Buffer.from(`${clientId}:${clientSecret}`).toString('base64');
const response = await fetch('https://auth.teoapp.fr/oauth2/token', {
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
'Authorization': `Basic ${credentials}`
},
body: `grant_type=client_credentials&scope=target-entity:${teoId}`
});
const { access_token, expires_in } = await response.json();
$clientId = 'votre_client_id';
$clientSecret = 'votre_client_secret';
$teoId = 'votre_teo_id';
$credentials = base64_encode("$clientId:$clientSecret");
$ch = curl_init('https://auth.teoapp.fr/oauth2/token');
curl_setopt_array($ch, [
CURLOPT_POST => true,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => [
'Content-Type: application/x-www-form-urlencoded',
"Authorization: Basic $credentials"
],
CURLOPT_POSTFIELDS => "grant_type=client_credentials&scope=target-entity:$teoId"
]);
$response = json_decode(curl_exec($ch));
$accessToken = $response->access_token;
import requests
import base64
client_id = 'votre_client_id'
client_secret = 'votre_client_secret'
teo_id = 'votre_teo_id'
credentials = base64.b64encode(f"{client_id}:{client_secret}".encode()).decode()
response = requests.post(
'https://auth.teoapp.fr/oauth2/token',
headers={
'Content-Type': 'application/x-www-form-urlencoded',
'Authorization': f'Basic {credentials}'
},
data=f'grant_type=client_credentials&scope=target-entity:{teo_id}'
)
data = response.json()
access_token = data['access_token']
Réponse
{
"access_token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",
"expires_in": 599,
"scope": "target-entity:votre_teo_id",
"token_type": "Bearer"
}
| Champ | Description |
|---|---|
access_token | Le token JWT à utiliser pour vos appels API |
expires_in | Durée de validité en secondes (10 minutes) |
token_type | Toujours Bearer |
Utiliser le token
Ajoutez le token dans le header Authorization de toutes vos requêtes :
GET https://teoapp.fr/api/production/dossiers
Authorization: Bearer {access_token}
Accept: application/ld+json
Bonne pratique
Réutilisez le même token jusqu'à son expiration plutôt que d'en demander un nouveau à chaque requête.
Gestion de l'expiration
Le token expire après 10 minutes. Voici comment gérer le renouvellement automatique :
let tokenCache = { token: null, expiresAt: 0 };
async function getToken() {
// Renouveler 1 minute avant expiration
if (tokenCache.token && Date.now() < tokenCache.expiresAt - 60000) {
return tokenCache.token;
}
const response = await fetchNewToken();
tokenCache = {
token: response.access_token,
expiresAt: Date.now() + response.expires_in * 1000
};
return tokenCache.token;
}
Erreurs courantes
| Erreur | Cause | Solution |
|---|---|---|
invalid_client | Identifiants incorrects | Vérifiez CLIENT_ID et CLIENT_SECRET |
invalid_scope | TEO_ID invalide | Vérifiez l'identifiant de votre instance |
expired_token | Token expiré | Demandez un nouveau token |
Pour plus de détails, consultez la page Gestion des erreurs.