You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I want to provide custom logic to retrieve the token used to access the Auth0 Management API. Yes, I can do this by calling "setApiToken()" but that's cumbersome. I would like to implement my own token provider by implementing TokenProvider, a public interface.
Describe the ideal solution
Add a method to the builder or add a constructor for the ManagementApi class (in the com.auth0.client.mgmt package), so that TokenProvider can be changed.
You can even just make the constructor on line 35 public, but I'd prefer a new constructor, as I don't need to specify the HTTP client.
You can literally fix this issue in 10 minutes or less.
Alternatives and current workarounds
No workarounds, except reflection, which is a hack.
Additional context
Please fix this quickly, thanks.
The text was updated successfully, but these errors were encountered:
Nice, I used Method Handles, which is better than reflection, @unkali:
/** * Used to access a private constructor for the Auth0 {@link ManagementAPI}, so that we can use our custom * {@link TokenProvider}. <br> Can be removed if * <a href="https://github.com/auth0/auth0-java/issues/669">Auth0 Java Repo - Issue #669</a> is addressed. */privatestaticfinalMethodHandleMANAGEMENT_API_CONSTRUCTOR_HANDLE;
static {
try {
MethodHandles.Lookuplookup = MethodHandles.lookup();
MethodHandles.LookuptargetLookup = MethodHandles.privateLookupIn(ManagementAPI.class, lookup);
MethodTypemethodType =
MethodType.methodType(void.class, String.class, TokenProvider.class, Auth0HttpClient.class);
MANAGEMENT_API_CONSTRUCTOR_HANDLE = targetLookup.findConstructor(ManagementAPI.class, methodType);
} catch (NoSuchMethodException | IllegalAccessExceptione) {
thrownewIllegalStateException("Failed to initialize MANAGEMENT_API_CONSTRUCTOR_HANDLE", e);
}
}
and then you call it like this:
try {
return (ManagementAPI) MANAGEMENT_API_CONSTRUCTOR_HANDLE.invoke(domain, tokenProvider, DefaultHttpClient.newBuilder().build());
} catch (Throwablee) {
thrownewIllegalStateException("Failed to construct the Auth0 ManagementAPI", e);
}
Checklist
Describe the problem you'd like to have solved
I want to provide custom logic to retrieve the token used to access the Auth0 Management API. Yes, I can do this by calling "setApiToken()" but that's cumbersome. I would like to implement my own token provider by implementing
TokenProvider
, a public interface.Describe the ideal solution
Add a method to the builder or add a constructor for the
ManagementApi
class (in thecom.auth0.client.mgmt
package), so thatTokenProvider
can be changed.You can even just make the constructor on line 35 public, but I'd prefer a new constructor, as I don't need to specify the HTTP client.
You can literally fix this issue in 10 minutes or less.
Alternatives and current workarounds
No workarounds, except reflection, which is a hack.
Additional context
Please fix this quickly, thanks.
The text was updated successfully, but these errors were encountered: