haase.dev/ blog

JWT Tokens With Keycloak

August 8, 2020

cURL

Generate JWT Token

Available grant_types can be found in the grant_types_supported section of /realms/$realm/.well-known/openid-configuration.

curl -X POST "https://auth.gernox.de/auth/realms/gernox/protocol/openid-connect/token" \
 -H "Content-Type: application/x-www-form-urlencoded" \
 -d "username=${USERNAME}" \
 -d "password=${PASSWORD}" \
 -d 'grant_type=password' \
 -d "client_id=api-test"

Source: https://medium.com/keycloak/keycloak-jwt-token-using-curl-post-72c9e791ba8c

Call API with JWT Token

curl -H 'Accept: application/json' -H "Authorization: Bearer ${TOKEN}" http://hello-world-api.test/api/world

Source: https://medium.com/@nieldw/using-curl-to-authenticate-with-jwt-bearer-tokens-55b7fac506bd