Skip to content

Conversation

@stephaneberle9
Copy link

Description

The Dynamic Client Registration (DCR) endpoint was ignoring the client's requested token_endpoint_auth_method parameter and consistently returning client_secret_basic, even when clients explicitly requested client_secret_post or other supported methods.

Root Cause

The issue occurred because:

  1. The client-secret authenticator in Keycloak supports both client_secret_basic and client_secret_post methods
  2. When converting the internal client representation to OIDC representation, the code called getProtocolAuthenticatorMethods() which returns a Set<String> containing both methods
  3. The code used .iterator().next() to get the first element, which always returned client_secret_basic due to LinkedHashSet ordering

Changes Made

Core Fix

  • DescriptionConverter.java:157-162: Store the requested token_endpoint_auth_method in client attributes during registration
  • DescriptionConverter.java:359-372: Retrieve and return the stored value in DCR responses
  • OIDCConfigAttributes.java:68: Add TOKEN_ENDPOINT_AUTH_METHOD constant

Backward Compatibility

  • Maintains full backward compatibility by falling back to the old behavior for clients registered before this fix
  • Existing clients will continue to work without any migration needed

Tests Added

  • OIDCClientRegistrationTest.java:352-390:
    • testClientSecretPostAuthMethod(): Verifies client_secret_post is stored and returned correctly
    • testClientSecretBasicAuthMethod(): Verifies client_secret_basic is stored and returned correctly

Testing

Manual Testing

You can verify the fix with this curl command:

curl -X POST http://localhost:8080/realms/{realm}/clients-registrations/openid-connect \
  -H "Content-Type: application/json" \
  -d '{
    "client_name": "Test Client",
    "redirect_uris": ["http://localhost:8000/callback"],
    "token_endpoint_auth_method": "client_secret_post"
  }'

Before fix: Response contains "token_endpoint_auth_method": "client_secret_basic"
After fix: Response contains "token_endpoint_auth_method": "client_secret_post"

Automated Tests

Two new test cases added to verify both client_secret_post and client_secret_basic are properly preserved.

Impact

This fix ensures RFC 7591 compliance and restores compatibility with:

  • Model Context Protocol (MCP) clients
  • OAuth clients requiring POST-based authentication
  • Environments with security policies mandating specific authentication methods

Compliance Checklist

Closes #44403

The Dynamic Client Registration (DCR) endpoint was ignoring the client's
requested token_endpoint_auth_method parameter and consistently returning
client_secret_basic, even when clients explicitly requested
client_secret_post or other methods.

This occurred because the client-secret authenticator supports both
client_secret_basic and client_secret_post, and the code was simply
returning the first method from the set (which was always
client_secret_basic due to LinkedHashSet ordering).

Changes:
- Store the requested token_endpoint_auth_method in client attributes
  during registration (toInternal method)
- Retrieve and return the stored value in the DCR response
  (toExternalResponse method)
- Add TOKEN_ENDPOINT_AUTH_METHOD constant to OIDCConfigAttributes
- Maintain backward compatibility by falling back to the old behavior
  for clients registered before this fix
- Add comprehensive tests for client_secret_post and client_secret_basic
  authentication methods

Closes keycloak#44403

Signed-off-by: Stephan Eberle <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

DCR endpoint ignores client's requested token_endpoint_auth_method

1 participant