简体   繁体   中英

Keycloak and Spring Boot authentication error

I run keycloak in a docker container and run my spring boot app from the idea. When I try to login in the keycloak form I get back an error

failed to turn code into token
status from server: 401
{"error":"unauthorized_client","error_description":"Client secret not provided in request"}

and the exception is: org.keycloak.adapters.springsecurity.KeycloakAuthenticationException: Invalid authorization header, see WWW-Authenticate header for details

Inside keycloak admin panels I have configured my users and roles.

The properties file:

keycloak.realm=myrealm
keycloak.resource=myclient
keycloak.auth-server-url=http://localhost:8081/auth
keycloak.ssl-required=external
keycloak.public-client=true
keycloak.principal-attribute=preferred_username
keycloak.credentials.secret=eba15252-we3r-423e-8df0-87f1da4a7c04
keycloak.use-resource-role-mappings=true

Could you please someone help how to fix this?

**UPDATE: if I run keycloak without docker it works.

Its clear, in the post request you are not entering client_secret. You should be able to get this from Clients section in Keycloak admin. Thats how your request should look like.

curl --location --request POST '{{KEYCLOAK_BASE_URL}}/auth/realms/{{KEYCLOAK_REALM}}/protocol/openid-connect/token' \
--data-urlencode 'grant_type=password' \
--data-urlencode 'client_id=web-app-client' \
--data-urlencode 'username=user@gmail.com' \
--data-urlencode 'password=123123' \
--data-urlencode 'client_secret=ea05b21c-fcb4-412d-acb7-c888ba7f996d' \
--data-urlencode 'scope=openid phone address'

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM