You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Keycloak Admin API should return details in case of 401 Unauthorized response
#41673
Sometimes developers fail to provide the access token in the right way. I observed various errors which were not easy to spot, when supporting developers who were stuck with a 401 Unauthorized response.
Let's take this example line in bash script: curl -v $KC_HOST/admin/realms/example/users/count --header "Authorization: Bearer $ACCESS_TOKEN"
The following bugs could be in the script:
Token is empty: Authorization: Bearer is sent
Variable not replaced: Authorization: Bearer $ACCESSS_TOKEN is sent
Complete token response send: Authorization: Bearer { "access_token"="ey...} is sent
Expired token sent
Wrong token sent (e.g. ID token or refresh token)
All those cases could be detected more easily with a helpful error description in the API response.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji
<
382E
tool-tip id="tooltip-2eedff5e-0d81-4b64-bf5e-3376ebc1dd4e" for="reactions--reaction_button_component-8a87c4" popover="manual" data-direction="s" data-type="description" data-view-component="true" class="sr-only position-absolute"> reacted with confused emoji
reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Sometimes developers fail to provide the access token in the right way. I observed various errors which were not easy to spot, when supporting developers who were stuck with a 401 Unauthorized response.
Let's take this example line in bash script:
curl -v $KC_HOST/admin/realms/example/users/count --header "Authorization: Bearer $ACCESS_TOKEN"The following bugs could be in the script:
Authorization: Beareris sentAuthorization: Bearer $ACCESSS_TOKENis sentAuthorization: Bearer { "access_token"="ey...}is sentAll those cases could be detected more easily with a helpful error description in the API response.
Actual Keycloak Response
In all of the cases above Keycloak response is
RFC 6750 Recommendation
RFC 6750 - The OAuth 2.0 Authorization Framework: Bearer Token Usage recommends to provide a WWW-Authenticate header which should be used to help debugging such faulty requests:
Example from RFC:
Proposal in case of 401 response
Admin API should sent the WWW-Authenticate header with error="invalid_token" and helpful error_description like the following:
Example Request:
Authorization: Bearer $ACCESSS_TOKENis sentExample response
All reactions