Naar hoofdinhoud gaan

Platform API-authenticatie (JWT)

De vitalera REST API gebruikt JWT (JSON Web Token)-authenticatie op basis van de OAuth 2.0-standaard.

Toegangsgegevens verkrijgen

Neem contact op met support@vitalera.io om het volgende aan te vragen:

  • Client ID — identificeert uw applicatie
  • Client Secret — authenticeert uw applicatie
  • Application ID — wordt gebruikt voor rotatie van toegangsgegevens

Client Credentials Grant

Voor server-naar-server (machine-to-machine) integraties:

curl -X POST "https://api.vitalera.io/api/auth/tokens/" \
-H "Content-Type: application/json" \
-d '{
"grant_type": "client_credentials",
"client_id": "<CLIENT_ID>",
"client_secret": "<CLIENT_SECRET>"
}'

Antwoord:

{
"access_token": "<ACCESS_TOKEN>",
"token_type": "Bearer",
"expires_in": 3600
}

Password Grant

Voor gebruikers-login-flows (bijv. mobiele of webapps die individuele gebruikers authenticeren):

curl -X POST "https://api.vitalera.io/api/auth/tokens/" \
-H "Content-Type: application/json" \
-d '{
"grant_type": "password",
"username": "<USERNAME>",
"password": "<PASSWORD>"
}'

Antwoord:

{
"id_token": "<ID_TOKEN>",
"access_token": "<ACCESS_TOKEN>",
"refresh_token": "<REFRESH_TOKEN>",
"sub": "<USER_ID>"
}

API-verzoeken uitvoeren

Voeg het access token toe aan de Authorization-header van elk verzoek:

curl -X GET "https://api.vitalera.io/api/plans/" \
-H "Authorization: Bearer <ACCESS_TOKEN>"

Tokengeldigheid

Access tokens zijn 1 uur (3600 seconden) geldig. Wanneer een token verloopt, geeft de API HTTP 401 Unauthorized terug:

{
"errors": [
{
"errorType": "expired_token",
"message": "Access token expired"
}
]
}

Tokenvernieuwing

Als u een refresh token heeft verkregen (via password grant), kunt u uw access token vernieuwen zonder opnieuw te authenticeren:

curl -X POST "https://api.vitalera.io/api/auth/tokens/refresh/" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer <ACCESS_TOKEN>" \
-d '{
"refresh_token": "<REFRESH_TOKEN>"
}'

Tokenvalidatie

Controleer of een token nog geldig is:

curl -X GET "https://api.vitalera.io/api/auth/tokens/validate/" \
-H "Authorization: Bearer <ACCESS_TOKEN>"

Rotatie van toegangsgegevens

Roteer regelmatig uw clienttoegangsgegevens voor de veiligheid. Dit vereist een geldig JWT en de application_id:

curl -X POST "https://api.vitalera.io/api/applications/rotate_credentials/" \
-H "Authorization: Bearer <ACCESS_TOKEN>" \
-H "Content-Type: application/json" \
-d '{
"application_id": "<APPLICATION_ID>"
}'

Antwoord:

{
"id": "<APPLICATION_ID>",
"name": "TestApp",
"organization": "123",
"client_id": "<NEW_CLIENT_ID>",
"client_secret": "<NEW_CLIENT_SECRET>",
"application_types": ["API"]
}

Na rotatie worden de vorige toegangsgegevens onmiddellijk ongeldig.


Hulp nodig?

Neem contact op met support@vitalera.io voor hulp bij de authenticatie-inrichting.