Autenticazione
Le API di Askme utilizzano il flusso OAuth 2.0 "Client Credentials" per ottenere un access token JWT che dovrà essere usato nelle richieste API autenticate.
Questa pagina descrive la procedura per ottenere il token dal realm Keycloak centrale di Askme.
Keycloak (Token endpoint)
Endpoint token (client credentials, application/x-www-form-urlencoded):
POST https://account.askmesuite.com/realms/askmesuite/protocol/openid-connect/token
Content-Type: application/x-www-form-urlencoded
Parametri (form data)
| Parametro | Valore | Descrizione |
|---|---|---|
grant_type | client_credentials | Tipo di grant da inviare |
client_id | string | Client ID fornito |
client_secret | string | Client secret fornito (se previsto) |
Esempio: richiesta con cURL
curl -X POST "https://account.askmesuite.com/realms/askmesuite/protocol/openid-connect/token" \
-H "Content-Type: application/x-www-form-urlencoded" \
-d "grant_type=client_credentials" \
-d "client_id=YOUR_CLIENT_ID" \
-d "client_secret=YOUR_CLIENT_SECRET"
Esempio: richiesta con Python (requests)
import requests
token_url = "https://account.askmesuite.com/realms/askmesuite/protocol/openid-connect/token"
payload = {
"grant_type": "client_credentials",
"client_id": "YOUR_CLIENT_ID",
"client_secret": "YOUR_CLIENT_SECRET"
}
resp = requests.post(token_url, data=payload, headers={"Content-Type": "application/x-www-form-urlencoded"})
resp.raise_for_status()
token_data = resp.json()
print(token_data)
Esempio: richiesta con JavaScript (axios)
const axios = require('axios');
const qs = require('qs');
const tokenUrl = 'https://account.askmesuite.com/realms/askmesuite/protocol/openid-connect/token';
const payload = qs.stringify({
grant_type: 'client_credentials',
client_id: 'YOUR_CLIENT_ID',
client_secret: 'YOUR_CLIENT_SECRET'
});
axios.post(tokenUrl, payload, { headers: { 'Content-Type': 'application/x-www-form-urlencoded' } })
.then(res => console.log(res.data))
.catch(err => console.error(err.response ? err.response.data : err.message));
Esempio di risposta (successo)
{
"access_token": "eyJhbGciOiJSUzI1NiIsInR5cC...",
"token_type": "Bearer",
"expires_in": 3600,
"scope": "chat:read chat:write chat:admin",
"issued_at": 1705078000
}
Uso del token nelle API
Dopo aver ottenuto access_token (JWT), includilo nelle richieste verso le API protette usando l'header Authorization: Bearer <access_token> oppure il meccanismo descritto nella pagina specifica del servizio se diverso.
Authorization: Bearer eyJhbGciOiJSUzI1NiIsInR5cC...
Validazione e JWKs
Per validare lato server le firme dei JWT, usa il JWKS endpoint del realm:
https://account.askmesuite.com/realms/askmesuite/protocol/openid-connect/certs
Errori comuni
invalid_client: client_id o client_secret erratiunauthorized_client: client non autorizzato per il grantinvalid_scope: scope non assegnati al client
Consigli di sicurezza
- Conserva
client_secretin secret manager o variabili d'ambiente - Usa HTTPS per tutte le comunicazioni
- Richiedi solo gli scope necessari