Oauth2/default/token request 400 error

Situation
I am trying to obtain an access token from the /oauth2/default/token endpoint in OpenEMR, but I consistently get a 400 Bad Request error with "invalid_client" or "Bad request" messages.

Steps I followed:

  1. Enabled required settings in Administration → Globals:
  • enable_oidc = 1
  • rest_api_token_endpoint_enable = 1
    2.(Verified in MySQL globals table.)*
  1. Registered a client via /oauth2/default/registration:
{
  "application_type": "private",
  "client_name": "Prevenotics AutoReport",
  "redirect_uris": ["http://localhost/callback"],
  "post_logout_redirect_uris": ["http://localhost/logout"],
  "response_types": ["code"],
  "token_endpoint_auth_method": "client_secret_post",
  "scope": "openid offline_access api:oemr"
}
  1. Confirmed that the generated client_id and client_secret match the entries in the MySQL oauth_clients table.
  2. Authorization Code request works — I get a code parameter back successfully.
  3. Tried to exchange the code for a token:
curl -X POST "https://localhost/openemr/oauth2/default/token" \
  -H "Content-Type: application/x-www-form-urlencoded" \
  -d "grant_type=authorization_code" \
  -d "code=xxxxxxxxxxxxxxxx" \
  -d "redirect_uri=http://localhost/callback" \
  -d "client_id=PnJlOAitpjuYwvQhzkxu5xVguswW-OaNEtr6KoOhdQU" \
  -d "client_secret=xxxxxxxxxxxxxxxx"
  1. Always get this response:
{
  "error": "invalid_client",
  "error_description": "Bad request",
  "message": "Bad request"
}

OpenEMR Version
7.0.3

Browser

  • Chrome Version 138
  • Also tested with curl from terminal

Operating System
macOS 15.0.1

Search
Yes — searched the forum and GitHub issues for “400 invalid_client token endpoint” but did not find a working solution for this case.

Logs
No detailed message in php_error.log — only the 400 response.
Checked MySQL oauth_clients table:

SELECT grant_types FROM oauth_clients WHERE client_id = 'PnJlOAitpjuYwvQhzkxu5xVguswW-OaNEtr6KoOhdQU';
-- Result:
authorization_code

Screenshot

please!!! somebody helps me, I’ve been living with a 400 error for a week.

I also face same error of Bad Request(Invalid request). Can anyone give solution for this.
@hikko Is your problem solved? If solved, can you pleae share the solution for that. I get error from past 6 days.