3

I followed this tutorial to setup Keycloak and create user but the response for the step of Generating Access Tokens With Keycloak's API 404. I'm using Keycloak version 18.0.0

In the logs of keycloak I found this error

2022-06-12 23:59:57,177 DEBUG [org.keycloak.services.error.KeycloakErrorHandler] (executor-thread-3) Error response 404: javax.ws.rs.NotFoundException: RESTEASY003210: Could not find resource for full path: http://localhost:8080/auth/realms/test/protocol/openid-connect/token

enter image description here

Sara Selim
  • 409
  • 5
  • 21

2 Answers2

8

From keycloak 17+ there are changes in resource or token URIs. Try removing auth from your request URL.

If you are using Keycloak version < 17

curl -k -H "Content-Type: application/x-www-form-urlencoded" -d "client_id=your-client" -d "username=some-user" -d "password=hardpassword" -d "grant_type=password" -X POST http://localhost:8080/auth/realms/yourrealm/protocol/openid-connect/token

If you are using Keycloak version > 17

curl -k -H "Content-Type: application/x-www-form-urlencoded" -d "client_id=your-client" -d "username=some-user" -d "password=hardpassword" -d "grant_type=password" -X POST http://localhost:8080/realms/yourrealm/protocol/openid-connect/token

Abhijeet
  • 4,069
  • 1
  • 22
  • 38
5

404 Error means the URL of the resource does not exist.

You did set in Headers instead of Body. Move the Key & Values to Body.enter image description here

In Keycloak version 18

You can verify Token URL by click "OpenID Endpoint Configuration" link enter image description here

It will show Token URL enter image description here

In Keycloak version 21

enter image description here

OIDC Well-Known Configuration Endpoint

Returns the OpenID Connect configuration values from the Keycloak's Well-Known Configuration Endpoint

GET /.well-known/openid-configuration
http://localhost:8080/realms/[your realm]/.well-known/openid-configuration

Token End Point

http://localhost:8080/realms/[your realm]/protocol/openid-connect/token

enter image description here

Get Access Token by Postman. enter image description here

Bench Vue
  • 5,257
  • 2
  • 10
  • 14