POST /api/mcp/oauth/token

Échanger un code d’autorisation ou renouveler un accès OAuth Smart BTP.

POST en formulaire, pas en JSON. Le champ resource doit valoir https://www.smartbtp.ai/api/mcp. Limite : 120 requêtes par minute. Corps plafonné à 16 Ko.

authorization_code

ChampRôle
grant_typeauthorization_code
codeCode reçu après l’accord, utilisable une fois, deux minutes.
redirect_uriLa même adresse que lors de l’autorisation.
code_verifierPreuve PKCE qui correspond au défi S256.
resourcehttps://www.smartbtp.ai/api/mcp
client_idIdentifiant reçu à l’enregistrement.

La réponse contient access_token, token_type valant Bearer, expires_in valant 3600, scope, et refresh_token si le client a demandé le renouvellement.

refresh_token

Mêmes client et resource. Le champ grant_type vaut refresh_token. Un scope facultatif ne peut que restreindre les droits. Réutiliser un ancien jeton de renouvellement révoque la connexion. La réponse ne contient alors pas un nouvel accès.

curl

curl
curl -s https://www.smartbtp.ai/api/mcp/oauth/token \
  -H 'Content-Type: application/x-www-form-urlencoded' \
  -d 'grant_type=authorization_code' \
  -d 'code=CODE_RECU' \
  -d 'redirect_uri=https://claude.ai/api/mcp/auth_callback' \
  -d 'code_verifier=VERIFICATEUR_PKCE' \
  -d 'resource=https://www.smartbtp.ai/api/mcp' \
  -d 'client_id=IDENTIFIANT_CLIENT'

JavaScript

JavaScript
const body = new URLSearchParams({
  grant_type: 'refresh_token',
  refresh_token: 'JETON_DE_RENOUVELLEMENT',
  resource: 'https://www.smartbtp.ai/api/mcp',
  client_id: 'IDENTIFIANT_CLIENT',
});
await fetch('https://www.smartbtp.ai/api/mcp/oauth/token', {
  method: 'POST',
  headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
  body,
});

Python

Python
import urllib.parse
from urllib.request import Request, urlopen

data = urllib.parse.urlencode({
    'grant_type': 'refresh_token',
    'refresh_token': 'JETON_DE_RENOUVELLEMENT',
    'resource': 'https://www.smartbtp.ai/api/mcp',
    'client_id': 'IDENTIFIANT_CLIENT',
}).encode()
request = Request(
    'https://www.smartbtp.ai/api/mcp/oauth/token',
    data=data,
    headers={'Content-Type': 'application/x-www-form-urlencoded'},
)
print(urlopen(request).read().decode())

Un client confidentiel envoie son secret en client_secret_post ou en client_secret_basic. Un client public, méthode none, ne présente pas de secret.