# Keycloak Fails (500 Internal Server Error) – But \`curl\` Works

**URL:** <https://forum.keycloak.org/t/keycloak-fails-500-internal-server-error-but-curl-works/29846>\
**Category:** Configuring the server\
**Tags:** authentication\
**Created:** [April 3, 2025, 7:23am UTC](https://forum.keycloak.org/t/keycloak-fails-500-internal-server-error-but-curl-works/29846 "2025-04-03T07:23:34Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![HGHG](https://avatars.discourse-cdn.com/v4/letter/h/a183cd/32.png) [@HGHG](https://forum.keycloak.org/u/HGHG)\
**Post date:** [April 3, 2025, 7:23am UTC](https://forum.keycloak.org/t/keycloak-fails-500-internal-server-error-but-curl-works/29846/1 "2025-04-03T07:23:34Z")

</div>

Hi everyone,

I’m trying to set up FreeRADIUS (v3.2.7) to authenticate users via Keycloak using the REST module and the OpenID Connect token endpoint. However, although authentication works fine when I use `curl`, it fails with a `500 Internal Server Error` when FreeRADIUS makes the request.

* * *

Server1 : FreeRADIUS (v3.2.7)

Server2 : Keycloak (v26.1.4)

OS : Rocky Linux release 8.10 (Green Obsidian)

* * *

### ✅ `curl` Works

```bash
curl -k -X POST https://<keycloak-host>:8443/realms/myrealm/protocol/openid-connect/token \
  -H "Content-Type: application/x-www-form-urlencoded" \
  -d "grant_type=password&client_id=<client-id>&client_secret=<client-secret>&username=testkim&password=1q2w3e4r"

```

This returns a valid `access_token`, so I know Keycloak is configured correctly.

* * *

### ❌ FreeRADIUS Fails

But when FreeRADIUS sends the same request, I get this error:

```auto
HTTP Request to /realms/myrealm/protocol/openid-connect/token failed
java.lang.IllegalArgumentException: Failed to parse media type form

```

In the FreeRADIUS debug logs:

```auto
(0) rest: Sending HTTP POST to "https://<keycloak-host>:8443/realms/myrealm/protocol/openid-connect/token"
(0) rest: Status : 500 (Internal Server Error)
(0) rest: ERROR: Server returned:
(0) rest: ERROR: {"details":"Error id <some-id>","stack":""}

```

* * *

### 🔧 My `mods-enabled/rest` Config

```conf
rest {
    connect_timeout = 4.0

    authenticate {
        uri = "https://<keycloak-host>:8443/realms/myrealm/protocol/openid-connect/token"
        method = "post"
        body = "form"
        data = "grant_type=password&client_id=<client-id>&client_secret=<client-secret>&username=%{request:User-Name}&password=%{request:User-Password}"
        header = "Content-Type: application/x-www-form-urlencoded"

        status_check_success = yes

        tls {
            ca_file = "/usr/local/etc/raddb/certs/keycloak.crt"
            check_cert = no
            check_cert_cn = no
        }
    }
}

```

* * *

### What I Tried

- Removed `connect_uri` and used full `uri`
- Verified headers and body match the `curl` request
- `curl` from the same server works fine
- TLS/cert verification is disabled for now

* * *

### My Guess

I suspect FreeRADIUS isn’t setting the `Content-Type` correctly — or something subtle in the REST call is different from `curl`.

* * *

### Question

Has anyone else encountered this? How can I debug what FreeRADIUS is really sending, or fix this media type error?

Thanks in advance!
