test_authorize.php nel browser o via URL con ?client_id=ID_CLIENT.authorize.php e cliccare "Login & Autorizza".callback.php con l’authorization code.callback.php scambia il code con access token e refresh token tramite token.php.resource.php o test_resource.php.refresh_token.php per ottenere un nuovo token. Se esiste già un token valido, verrà restituito quello esistente con il tempo residuo aggiornato.GET /resource.php
Authorization: Bearer ACCESS_TOKEN
L’API risponderà con i dati dell’utente se il token è valido e ha i permessi corretti.
curl -X GET "http://localhost/api-sa/public/authorize.php?client_id=ID_CLIENT"
Risposta tipica (redirect al callback con authorization code):
HTTP/1.1 302 Found
Location: http://localhost/api-sa/public/callback.php?code=AUTH_CODE
curl -X POST "http://localhost/api-sa/public/token.php" \
-d "grant_type=authorization_code" \
-d "code=AUTH_CODE" \
-d "client_id=ID_CLIENT" \
-d "client_secret=CLIENT_SECRET"
Risposta JSON:
{
"access_token": {
"value": "ACCESS_TOKEN",
"token_type": "Bearer",
"expires_in": 3600
},
"refresh_token": {
"value": "REFRESH_TOKEN",
"token_type": "Bearer",
"expires_in": 2592000
}
}
curl -X GET "http://localhost/api-sa/public/resource.php" \
-H "Authorization: Bearer ACCESS_TOKEN"
Risposta JSON:
{
"message": "Accesso riuscito!",
"user_id": 123
}
curl -X POST "http://localhost/api-sa/public/refresh_token.php" \
-d "client_id=ID_CLIENT" \
-d "refresh_token=REFRESH_TOKEN"
Risposta JSON:
{
"access_token": {
"value": "NEW_ACCESS_TOKEN",
"token_type": "Bearer",
"expires_in": 3600
}
}
error nel JSON.test_authorize.php e test_resource.php servono per verificare velocemente il flusso completo.