Authentication
Comment s'authentifier auprès de l'API ITCare ?
Pour interroger l'API ITCare, un compte API est requis afin de pouvoir obtenir le token d'accès obligatoire.\
Pour obtenir ce compte API, une requête doit être soumise aux équipes support **cegedim.cloud** en fournissant les informations suivantes :
* L'organisation cible
* Une description simple de l'usage cible de l'API
## Comment obtenir un token d'accès ? <a href="#apiitcare-commentobteniruntokendacces" id="apiitcare-commentobteniruntokendacces"></a>
Pour obtenir un token d'accès, le client doit soumettre une requête au endpoint [/token](https://accounts.cegedim.cloud/auth/realms/cloud/protocol/openid-connect/token).\
Le serveur d'autorisation exige l'authentification (base64-encodé) du client pour délivrer un access\_token.\
Voici un exemple de demande d'access\_token :<div data-gb-custom-block data-tag="code" data-overflow='wrap'>```bash
curl -X POST "https://accounts.cegedim.cloud/auth/realms/cloud/protocol/openid-connect/token" \
-H "Authorization: Basic $(echo -n 'CLIENT_ID:CLIENT_SECRET' | base64)" \
-H "Content-Type: application/x-www-form-urlencoded" \
-d "grant_type=client_credentials"
```</div>En général, on peut utiliser la commande base64 pour encoder une chaîne de caractères.\
L'utilisation d'outils en ligne de commande sous Linux, par exemple :<div data-gb-custom-block data-tag="code" data-overflow='wrap'>```bash
$echo -n 'CLIENT_ID:CLIENT_SECRET' | base64
(donne la base64 du couple CLIENT_ID:CLIENT_SECRET)
```</div>Si la demande d'access\_token est autorisée et valide, voici un exemple de réponse :<div data-gb-custom-block data-tag="code" data-overflow='wrap'>```json
{
"access_token":"...",
"expires_in":1200,
"refresh_expires_in":7200,
"refresh_token":"...",
"token_type":"bearer"
}
```</div>Lorsque le token expire, il est possible de :
* Demander un nouvel access\_token
* Rafraîchir le token en interrogeant le endpoint /token<div data-gb-custom-block data-tag="code" data-overflow='wrap'>```bash
curl -X POST "https://accounts.cegedim.cloud/auth/realms/cloud/protocol/openid-connect/token" \
-H "Authorization: Basic $(echo -n 'CLIENT_ID:CLIENT_SECRET' | base64)" \
-H "Content-Type: application/x-www-form-urlencoded" \
-d "grant_type=client_credentials&refresh_token=****************"
```</div>Last updated

