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

Postman调用Keycloak API遇400错误,提示grant_type参数缺失求助

Fixing "Missing form parameter: grant_type" Error in Keycloak Token API Call

Hey there, let's get this 400 error sorted out for you. The issue here is a common gotcha with OAuth2 password grant flows and how Keycloak expects parameters to be sent.

What's Going Wrong

Even though you included all the required parameters in the URL query string and set the right Content-Type header, Keycloak's token endpoint doesn't accept grant-type parameters via URL query parameters for the password flow. It expects these values to be sent as form data in the request body instead.

Step-by-Step Fix

Here's exactly what to adjust in Postman:

  1. Use the correct request method: Make sure your request is set to POST (not GET) — this is required for the password grant flow.
  2. Remove parameters from the URL: Trim your request URL down to just the base endpoint:
    http://{hostname}:8080/auth/realms/master/protocol/openid-connect/token
    
  3. Add parameters to the request body:
    • Switch to the "Body" tab in Postman
    • Select the x-www-form-urlencoded option (Postman will automatically set the correct Content-Type header for you, so you don't need to manually add it)
    • Add these key-value pairs one by one:
      • username: admin
      • password: admin
      • client_id: admin-cli
      • grant_type: password
  4. Send the request: You should now get a valid token response instead of the 400 error.

Extra Checks (If It Still Fails)

  • If you're using Keycloak 17 or newer, note that the /auth prefix was removed from the API path. Your URL should be:
    http://{hostname}:8080/realms/master/protocol/openid-connect/token
    
  • Verify that the admin user in the master realm has the correct password, and that the admin-cli client is enabled in Keycloak's admin console.
  • Double-check that Postman isn't sending any conflicting custom headers that might interfere with the request.

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.20 10:07:28