You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Spring Boot中通过Keycloak REST API获取AccessToken遇404问题

Answer

Hey there, the 404 error you're hitting is almost always related to a path mismatch or service availability—let's break down the most likely fixes:

1. Fix the Token API Path Based on Your Keycloak Version

This is the #1 culprit here. Keycloak changed its default URL structure starting in version 17 (the Quarkus-based rewrite):

  • If you're using Keycloak 17 or newer: The /auth prefix was removed entirely. Your token request URL should be:
    http://localhost:8180/realms/springboot/protocol/openid-connect/token
    
  • If you're on Keycloak 16 or older: Your original URL with /auth is correct—skip to the next checks.

You can confirm your Keycloak version by checking the admin console login screen or running keycloak version in your terminal.

2. Make Sure Keycloak is Running and Reachable

First, test if you can access the Keycloak admin console:

  • Older versions: Visit http://localhost:8180/auth/admin
  • Newer versions: Visit http://localhost:8180/admin

If the console doesn't load, your server isn't running on port 8180, or there's a network block stopping access.

3. Double-Check Your Keycloak Realm/Client Settings

Even if the path is right, these configs can break your request:

  • Realm Name: Ensure the realm you created is exactly springboot—realm names are case-sensitive!
  • Client Configuration:
    • For your springboot client, make sure Direct Access Grants Enabled is turned ON (this is mandatory for the password grant type to work).
    • Confirm the client_id in your Postman request matches the client ID in Keycloak (you've set it to springboot, which aligns with your app config).
    • If your client is set to confidential (not public), you'll need to add a client_secret parameter to your Postman request body (you can find this secret in the client's "Credentials" tab in Keycloak).

4. Align Your Spring Boot Config with Keycloak Version

Your app's keycloak.auth-server-url uses /auth—if you're on Keycloak 17+, update this property to:

keycloak.auth-server-url=http://localhost:8180

Give these steps a try, and the 404 should disappear once the path and configs are aligned!

内容的提问来源于stack exchange,提问作者Thejus32

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.14 08:41:32