auth0 / auth0-java

Java client library for the Auth0 platform
https://auth0.com
MIT License
295 stars 130 forks source link

ManagementAPI getLogEvents() is double encoding the LogEventFilter's withQuery() value #419

Closed CalebeGeazi closed 2 years ago

CalebeGeazi commented 2 years ago

Describe the problem you'd like to have solved

When building a LogEventFilter object that adds a date range query via the LogEventsFilter.withQuery() method, and then passing this object to the ManagementAPI getLogEvents() method the resulting q query string parameter is being double encoded. This is causing a 400 Bad Request error.

Reproduction

Here's the code snippet for setting the query parameter and making the getLogEvents() call:

LocalDate date = LocalDate.now().minus(Period.ofDays(30));
String query = "date:[" + date + " TO *]";
LogEventFilter filter = new LogEventFilter()
    .withQuery(query)
    .withPage(pageNumber, 10);

Request<LogEventsPage> request = managementApi.users().getLogEvents(userId, filter);
request.execute();

Environment

Describe the ideal solution

I would expect the query to only be URLEncoded once.

Alternatives and current work-arounds

Manually build the request to call the /users/{user-id}/logs endpoint.

jimmyjames commented 2 years ago

Thanks for reporting this. Looks like the issue is that in QueryFilter#withQuery we encode the query, but then re-encode it in getLogEvents with addQueryParameter. Quick fix may be to do what we do in UsersEntity#list, checking if the param name is the query key and not encoding that param.

jimmyjames commented 2 years ago

This will be fixed with #420 which will be available in 1.41.0, which will be available in maven central shortly. Thanks!