Skip to content

Conversation

@adenix
Copy link
Contributor

@adenix adenix commented Oct 7, 2025

Changes

This PR adds a new constructor to the Client class that allows setting the clientId at construction time.

Problem:
The Auth0 Management API allows users to specify a custom client_id when creating a new client. However, the current SDK does not provide a way to set this value without using reflection, forcing users to write code like this:

// Current workaround using reflection
Client client = new Client("My App");
// The Auth0 SDK does not provide a setter for 'clientId' though the
// API does allow setting a custom value.
Field clientIdField = Client.class.getDeclaredField("clientId");
clientIdField.setAccessible(true);
clientIdField.set(client, "custom-client-id");

Solution:
This PR provides a clean, type-safe way to set the clientId during construction without requiring reflection.

Classes and methods added:

  • Added Client(String name, String clientId) constructor with JavaDoc

Summary of usage:

// Existing usage - still works (backward compatible)
Client client = new Client("My App");
// client.getName() == "My App"
// client.getClientId() == null

// New usage - can now set clientId at construction (no reflection needed!)
Client client = new Client("My App", "custom-client-id");
// client.getName() == "My App"
// client.getClientId() == "custom-client-id"

The clientId field remains immutable as intended - there is no setter method, and it can only be set during object construction using the new constructor. The existing single-parameter constructor remains unchanged and continues to work as before for complete backward compatibility.

References

Testing

This change has been tested with comprehensive unit tests covering both the new functionality and backward compatibility:

  • This change adds test coverage
    • Added shouldCreateClientWithNameOnly() to verify backward compatibility
    • Added shouldCreateClientWithNameAndClientId() to verify the new constructor sets both fields correctly
  • This change has been tested on the latest version of the platform/language
    • All tests pass with Java 8+
    • Verified with ./gradlew test --tests ClientTest

Test coverage includes:

  • Verification that existing single-parameter constructor still works as expected
  • Verification that clientId remains null when using single-parameter constructor
  • Verification that new two-parameter constructor sets both name and clientId correctly
  • All existing tests continue to pass without modification

Checklist

@adenix adenix requested a review from a team as a code owner October 7, 2025 01:14
Add new constructor Client(String name, String clientId) to allow
setting the immutable clientId field during object construction.

The existing Client(String name) constructor remains unchanged to
maintain backward compatibility. This allows users to optionally
set the clientId at construction time when needed, while the field
remains immutable (no setter exists).

- Add Client(String name, String clientId) constructor with JavaDoc
- Add test for backward compatibility (existing constructor)
- Add test for new constructor functionality
- All existing tests continue to pass
@adenix adenix force-pushed the feature/client-id-constructor branch from f063b0b to aebe732 Compare October 7, 2025 03:46
@adenix
Copy link
Contributor Author

adenix commented Oct 7, 2025

This adds support for #778

@tanya732
Copy link
Contributor

LGTM !!

@tanya732
Copy link
Contributor

Closing this PR, as fix has been released in v2.26.0 in #781

@tanya732 tanya732 closed this Oct 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants