Getting access to API 2.0
To retrieve an authorization token for Rest calls, send a POST request to `https://keycloak.staging-adhese.org/realms/adhese-guineapig/protocol/openid-connect/token` with the parameters:api/oauth/token
- username
- password
- client_id=
frontendadhese-app - grant_type=password
Using curl:
curl --datalocation "username=foo&password=bar&client_id=frontend&grant_type=password" 'https://subdomain.keycloak.staging-adhese.org/api/oauth/tokenrealms/adhese-guineapig/protocol/openid-connect/token' \
--header 'Content-Type: application/x-www-form-urlencoded' \
--data-urlencode 'client_id=adhese-app' \
--data-urlencode 'grant_type=password' \
--data-urlencode 'username=username' \
--data-urlencode 'password=password'
You will get back an access token:
{
"access_token": "123456",
"token_type": "bearer",
"expires_in": 42237,
"scope": "read write"
}
To execute Rest requests that require authorization, add an Authorization header with value Bearer <access_token>, where <access_token> is the access_token returned by the above request.request and add
curlUse-Keycloak-Auth-Hheader"Authorization:Bearerwith<access_token>"valuehttps://subdomain.adhese.org/api/...true
To test against localhost, use
curl --datalocation "username=admin&password=admin&client_id=frontend&grant_type=password" http:'https://localhost:8080/guineapig.staging-adhese.org/api/oauth/tokenusers/me' \
--header 'Use-Keycloak-Auth: true' \
--header 'Authorization: Bearer <access_token>'