Autenticazione

Metodi di autenticazione

CodeRS supporta tre metodi di autenticazione:

Metodo Uso consigliato
API Key Server-to-server, script CI
OAuth 2.0 Applicazioni di terze parti
JWT Sessioni utente brevi

API Key

Generazione

coders api-key create --name "my-ci-script"
# ck_live_abc123...

Utilizzo

curl https://api.coders.dev/v1/projects \
  -H "Authorization: Bearer ck_live_abc123..."
const coders = new CodersClient({
  apiKey: process.env.CODERS_API_KEY,
});

OAuth 2.0

Authorization Code Flow

GET https://auth.coders.dev/oauth/authorize
  ?client_id=CLIENT_ID
  &redirect_uri=https://yourapp.com/callback
  &response_type=code
  &scope=projects:read deployments:write
  &state=RANDOM_STATE

Token exchange

curl -X POST https://auth.coders.dev/oauth/token \
  -d grant_type=authorization_code \
  -d code=AUTH_CODE \
  -d client_id=CLIENT_ID \
  -d client_secret=CLIENT_SECRET \
  -d redirect_uri=https://yourapp.com/callback

Risposta

{
  "access_token": "eyJ...",
  "token_type": "Bearer",
  "expires_in": 3600,
  "refresh_token": "dGhp...",
  "scope": "projects:read deployments:write"
}

Rate limiting

Ogni API key ha un limite di 1000 richieste/minuto. I header di risposta indicano lo stato:

X-RateLimit-Limit: 1000
X-RateLimit-Remaining: 847
X-RateLimit-Reset: 1712345678