Authorization via curl
Request an access token using the OAuth2 password grant. Use --data-urlencode for each form field so special characters are encoded locally.
Example
curl "https://api-dev.lifepeaks.dk/token" \
--data-urlencode "client_id=$LIFEPEAKS_CLIENT_ID" \
--data-urlencode "client_secret=$LIFEPEAKS_CLIENT_SECRET" \
--data-urlencode 'grant_type=password' \
--data-urlencode "username=$LIFEPEAKS_USERNAME" \
--data-urlencode "password=$LIFEPEAKS_PASSWORD"
Response example:
{
"access_token": "<access-token>",
"expires_in": 86400,
"token_type": "Bearer",
"scope": "admin",
"refresh_token": "<refresh-token>"
}
Refreshing the token
When the access token expires after 24 hours, exchange the refresh token rather than sending the credentials again. A new refresh token is issued each time, so store the one from the latest response.
curl "https://api-dev.lifepeaks.dk/token" \
--data-urlencode "client_id=$LIFEPEAKS_CLIENT_ID" \
--data-urlencode "client_secret=$LIFEPEAKS_CLIENT_SECRET" \
--data-urlencode 'grant_type=refresh_token' \
--data-urlencode "refresh_token=$LIFEPEAKS_REFRESH_TOKEN"
Troubleshooting
If the API returns “Invalid username and password combination”, check the credentials and use --data-urlencode as shown above. Keep credentials on your server; do not enter them into external encoding websites.
The token endpoint accepts POST requests. Supplying form data with curl selects POST automatically.