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
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 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: Bearer
is sentAuthorization: Bearer $ACCESSS_TOKEN
is 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_TOKEN
is sentExample response
Beta Was this translation helpful? Give feedback.
All reactions