簡體   English   中英

帶有 spring 啟動 CODE_TO_TOKEN_ERROR 的 Keycloak

[英]Keycloak with spring boot CODE_TO_TOKEN_ERROR

與 spring-boot 應用程序集成密鑰斗篷,但在嘗試登錄時出現以下錯誤。 需要幫助解決“CODE_TO_TOKEN_ERROR”。

在 keycloak 服務器日志中:

2019-09-25 15:38:25,040 WARN  [org.keycloak.events] (default task-19) type=CODE_TO_TOKEN_ERROR, realmId=Test-App, clientId=test-web-app, userId=null, ipAddress=127.0.0.1, error=invalid_client_credentials, grant_type=authorization_code

在 spring 啟動應用程序日志中:

2019-09-25 15:38:25.042 ERROR 3666 --- [nio-8081-exec-1] o.k.adapters.OAuthRequestAuthenticator   : failed to turn code into token
2019-09-25 15:38:25.042 ERROR 3666 --- [nio-8081-exec-1] o.k.adapters.OAuthRequestAuthenticator   : status from server: 400
2019-09-25 15:38:25.042 ERROR 3666 --- [nio-8081-exec-1] o.k.adapters.OAuthRequestAuthenticator   :    {"error":"unauthorized_client","error_description":"Client secret not provided in request"}

application.properties 文件:

keycloak.auth-server-url = http://localhost:8080/auth
keycloak.realm = Test-App
keycloak.resource = test-web-app
keycloak.credentials.secret = xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxx
keycloak.ssl-required = external
keycloak.use-resource-role-mappings = true
keycloak.public-client = true

keycloak.security-constraints[0].authRoles[0] = ROLE_USER
keycloak.security-constraints[0].securityCollections[0].patterns[0] = /hello/*

server.port = 8081

Made POST request to http://localhost:8080/auth/realms/{realm-name}/protocol/openid-connect/token URL from postman by adding following parameters to the x-www-form-urlencoded section of body part.

標題:

Content-Type: application/x-www-form-urlencoded

身體參數:

client_id:new-realm-app
username:username
password:password
grant_type:password
client_secret:xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx

生成了一個 access_token。 就是這樣。。

它對我有用...

您需要刪除此屬性 keycloak.public-client = true,公共客戶端僅在客戶端是在瀏覽器客戶端中運行的客戶端時使用,如 javascript 應用程序(Angular 或反應)。 當您使用此屬性時,keycloak 不會在身份驗證請求中發送客戶端 ID 和憑據。 如果您有 spring 引導服務,則需要使用機密或僅承載客戶端。 您可以在keycloak 文檔中閱讀更多內容

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM