Getting 404 not found error while accessing keycloak API method

Using Postman I'm accessing the keycloak API method for reasoning to avoid the key cloak page as login page in my angular application. I'm getting access_token from belonging to the master realm but while accessing the other realm (created for specific to the angular application) with token as the Authorization Bearer Token my request, getting 404 not found error.

Note: If I add any junk value append in token It says that 401 unauthorized

Screenshot from Postman:

got access_token from master realm

accessing other realm with bearer token

Upvotes: 4

Views: 20434

Answers (1)

Jijie Chen
Jijie Chen

Reputation: 449

There should be a base path /auth/admin/realms/ when using their RESTful API. The /admin/realms part was missing from the base path stated in their documents.

  1. Obtain an access token using this endpoint: /auth/realms/master/protocol/openid-connect/token
  2. Using the token to invoke the RESTful admin APIs.
KEYCLOAK_TOKEN=$(curl -X POST "${KEYCLOAK_URL}/auth/realms/master/protocol/openid-connect/token" \
 -H "Content-Type: application/x-www-form-urlencoded" \
 -d "username=admin" \
 -d "password=admin-password" \
 -d 'grant_type=password' \
 -d 'client_id=admin-cli' | jq -r '.access_token')

curl "${KEYCLOAK_URL}/auth/admin/realms/${KEYCLOAK_REALM}/users" -H "Authorization: Bearer ${KEYCLOAK_TOKEN}" 

Upvotes: 6

Related Questions