The version 2 release includes several notable improvements, including:
- Requests can now be configured with additional parameters and headers, without needing to downcast to
CustomRequest. - Responses are now wrapped in a new
com.auth0.net.Responsetype, which provides information about the HTTP response such as headers and status code. - The
AuthAPIandManagementAPIclients can now share the same HTTP client. - The
AuthAPIclient no longer requires a client secret, enabling support for APIs and scenarios where a secret is not required.
Version 2 includes breaking changes. Please read this guide to learn how to update your application for v2.
To create the API clients, use the new builders, and specify any HTTP-related configurations with the new DefaultHttpClient:
Auth0HttpClient http = DefaultHttpClient.newBuilder()
.withConnectTimeout(10)
.withReadTimeout(10)
// additional configurations as needed
.build();
AuthAPI auth = AuthAPI.newBuilder("{DOMAIN}", "{CLIENT-ID}", "{OPTIONAL-CLIENT-SECRET}")
.withHttpClient(http)
.build();
ManagementAPI mgmt = ManagementAPI.newBuilder("{DOMAIN}", "{API-TOKEN}")
.withHttpClient(http)
.build();Version 2 returns HTTP response information such as status code and headers in a new com.auth0.net.Response type.
Instead of simply returning the parsed JSON response body from requests, all API methods now return a Response<T>.
If you have no need for the response information, replace any calls to execute() with execute().getBody() to get the returned response body as before:
// Get response info
Response<User> userResponse = api.users().get("{USER-ID}", null);
int code = userResponse.getStatusCode();
Map<String, String> headers = userResponse.getHeaders();
// Just get the response body
User user = api.users().get("{USER-ID}", null).execute().getBody();Previously, only requests that returned a CustomizableRequest (or its implementation, CustomRequest) allowed for a request to be configured with additional parameters or headers.
In v2, the com.auth0.net.Request interface defines the new methods:
Request<T> addHeader(String name, String value)Request<T> addParameter(String name, Object value)Request<T> setBody(Object body)
This enables all requests to be configured, without the need to downcast to CustomizableRequest or CustomRequest.
If you were down-casting to these types, you will need to remove the cast and instead configure the request directly:
Request<User> userRequest = api.users().get("{USER-ID}", null);
userRequest.addHeader("some-header", "some-value");
Response<User> userResponse = userRequest.execute();The following summarizes details of the changes in version 2, including types and methods removed, added, or deprecated.
AuthRequesthas been removed. UseTokenRequestinstead.CustomizableRequestandCustomRequesthave been removed. TheRequestinterface now supports request customization directly without the need to downcast.FormDataRequesthas been removed. UseMultipartRequestinstead.CreateUserRequesthas been removed. UseSignUpRequestinstead.
com.auth0.json.mgmt.Tokenmoved tocom.auth0.json.mgmt.blacklists.Tokencom.auth0.json.mgmt.ClientGrantmoved tocom.auth0.json.mgmt.clientgrants.ClientGrantcom.auth0.json.mgmt.ClientGrantsPagemoved tocom.auth0.json.mgmt.clientgrants.ClientGrantsPagecom.auth0.json.mgmt.Connectionmoved tocom.auth0.json.mgmt.connections.Connectioncom.auth0.json.mgmt.ConnectionsPagemoved tocom.auth0.json.mgmt.connections.ConnectionsPagecom.auth0.json.mgmt.DeviceCredentialsmoved tocom.auth0.json.mgmt.devicecredentials.DeviceCredentialscom.auth0.json.mgmt.EmailTemplatemoved tocom.auth0.json.mgmt.emailtemplates.EmailTemplatecom.auth0.json.mgmt.Grantmoved tocom.auth0.json.mgmt.grants.Grantcom.auth0.json.mgmt.GrantsPagemoved tocom.auth0.json.mgmt.grants.GrantsPagecom.auth0.json.mgmt.EmailVerificationIdentitymoved tocom.auth0.json.mgmt.tickets.EmailVerificationIdentitycom.auth0.json.mgmt.Key;moved tocom.auth0.json.mgmt.keys.Keycom.auth0.json.mgmt.RolesPagemoved tocom.auth0.json.mgmt.roles.RolesPagecom.auth0.json.mgmt.ResourceServermoved tocom.auth0.json.mgmt.resourceserver.ResourceServercom.auth0.json.mgmt.ResourceServersPagemoved tocom.auth0.json.mgmt.resourceserver.ResourceServersPagecom.auth0.json.mgmt.Permissionmoved tocom.auth0.json.mgmt.permissions.Permissioncom.auth0.json.mgmt.PermissionsPagemoved tocom.auth0.json.mgmt.permissions.PermissionsPagecom.auth0.json.mgmt.Rolemoved tocom.auth0.json.mgmt.roles.Rolecom.auth0.json.mgmt.RolesPagemoved tocom.auth0.json.mgmt.roles.RolesPagecom.auth0.json.mgmt.RulesConfigmoved tocom.auth0.json.mgmt.rules.RulesConfigcom.auth0.json.mgmt.Rulemoved tocom.auth0.json.mgmt.rules.Rulecom.auth0.json.mgmt.RulesPagemoved tocom.auth0.json.mgmt.rules.RulesPagecom.auth0.json.mgmt.DailyStatsmoved tocom.auth0.json.mgmt.stats.DailyStatscom.auth0.json.mgmt.Permissionmoved tocom.auth0.json.mgmt.permissions.Permissioncom.auth0.json.mgmt.PermissionsPagemoved tocom.auth0.json.mgmt.permissions.PermissionsPagecom.auth0.json.mgmt.RolesPagemoved tocom.auth0.json.mgmt.roles.RolesPage
void com.auth0.client.mgmt.ManagementAPI#doNotSendTelemetry()has been removed. Telemetry configuration can be done using theDefaultHttpClient#Buildervoid com.auth0.client.auth.AuthAPI#doNotSendTelemetry()has been removed. Telemetry configuration can be done using theDefaultHttpClient#Buildervoid com.auth0.client.mgmt.ManagementAPI#setTelemetry(Telemetry telemetry)has been removed. Telemetry configuration can be done using theDefaultHttpClient#Buildervoid com.auth0.client.auth.AuthAP#setTelemetry(Telemetry telemetry)has been removed. Telemetry configuration can be done using theDefaultHttpClient#Builder- Deprecated
void com.auth0.client.mgmt.ManagementAPI#setLoggingEnabled(boolean enabled)has been removed. Telemetry configuration can be done using theDefaultHttpClient#Builder - Deprecated
void com.auth0.client.auth.AuthAPI#setLoggingEnabled(boolean enabled)has been removed. Telemetry configuration can be done using theDefaultHttpClient#Builder - Deprecated
Request<List<ClientGrant>> com.auth0.client.mgmt.ClientGrantsEntity#list()has been removed. UseRequest<ClientGrantsPage> list(ClientGrantsFilter filter) com.auth0.client.mgmt.ClientGrantsEntity#list(ClientGrantsFilter filter)instead. - Deprecated
Request<List<Client>> com.auth0.client.mgmt.ClientsEntity#list()has been removed. UseRequest<ClientsPage> com.auth0.client.mgmt.ClientsEntity#list(ClientFilter filter)instead. - Deprecated
Request<List<Connection>> com.auth0.client.mgmt.ClientsEntity#list(ConnectionFilter filter)has been removed. UseRequest<ConnectionsPage> com.auth0.client.mgmt.ClientsEntity#listAll(ConnectionFilter filter)instead. - Deprecated
Request<List<Grant>> com.auth0.client.mgmt.GrantsEntity#list(String userId)has been removed. UseRequest<GrantsPage> com.auth0.client.mgmt.GrantsEntity#list(String userId, GrantsFilter filter)instead. - Deprecated
Request<List<ResourceServer>> com.auth0.client.mgmt.ResourceServerEntity#list()has been removed. UseRequest<ResourceServersPage> com.auth0.client.mgmt.ResourceServersEntity#list(ResourceServersFilter)instead. - Deprecated
Request<List<Rule>> com.auth0.client.mgmt.RulesEntity#list(RulesFilter filter)has been removed. UseRequest<RulesPage> com.auth0.client.mgmt.RulesEntity#listAll(RulesFilter filter)instead. - Deprecated
void com.auth0.json.mgmt.guardian.EnrollmentTicket#setUserId(String id)has been removed. Use the constructor instead. - Deprecated
com.auth0.json.mgmt.guardian.SNSFactorProviderno-arg constructor has been removed. Use the full constructor instead. - Deprecated
void com.auth0.json.mgmt.guardian.SNSFactorProvider#setAWSAccessKeyId(String awsAccessKeyId)has been removed. Use the constructor instead. - Deprecated
void com.auth0.json.mgmt.guardian.SNSFactorProvider#setAWSSecretAccessKey(String awsSecretAccessKey)has been removed. Use the constructor instead. - Deprecated
void com.auth0.json.mgmt.guardian.SNSFactorProvider#setAWSRegion(String awsRegion)has been removed. Use the constructor instead. - Deprecated
void com.auth0.json.mgmt.guardian.SNSFactorProvider#setSNSAPNSPlatformApplicationARN(String apnARN)has been removed. Use the constructor instead. - Deprecated
void com.auth0.json.mgmt.guardian.SNSFactorProvider#setSNSGCMPlatformApplicationARN(String gcmARN)has been removed. Use the constructor instead. - Deprecated
com.auth0.json.mgmt.guardian.TwilioFactorProviderno-arg constructor has been removed. Use the full constructor instead. - Deprecated
void com.auth0.json.mgmt.guardian.TwilioFactorProvider#setFrom(String from)has been removed. Use the constructor instead. - Deprecated
void com.auth0.json.mgmt.guardian.TwilioFactorProvider#setMessagingServiceSID(String messagingServiceSID)has been removed. Use the constructor instead. - Deprecated
void com.auth0.json.mgmt.guardian.TwilioFactorProvider#setAuthToken(String authToken)has been removed. Use the constructor instead. - Deprecated
void com.auth0.json.mgmt.guardian.TwilioFactorProvider#setSID(String SID)has been removed. Use the constructor instead. - The default implementation of
com.auth0.net.Request#executeAsync()has been removed; implementations must provide an implementation ofexecuteAsync.
Version 2 introduces a new abstraction, com.auth0.net.client.Auth0HttpClient, to handle the core HTTP responsibilities of sending HTTP requests.
An implementation is provided in DefaultHttpClient, which supports all the configurations available in the now-deprecated HttpOptions.
In addition to these configurations, it is also possible to implement the Auth0HttpClient for advanced use-cases where the default implementation or its configurations are not sufficient.
Several new types have been added to support this:
com.auth0.net.client.Auth0HttpClienthas been added to define the HTTP client interface.com.auth0.net.client.DefaultHttpClientis the default HTTP implementation that should be used in the majority of cases. It supports the same configurations asHttpOptions, but can be reused across API clients. It usesOkHttpas the networking client internally.com.auth0.net.client.Auth0HttpRequestis a lightweight representation of an HTTP request to execute. Internal API implementations will form the request.com.auth0.net.client.Auth0HttpResponseis a lightweight representation of an HTTP response. Internal API implementations will parse the response.com.auth0.net.client.HttpMethodis anenumrepresenting the HTTP methods.
com.auth0.client.HttpOptionshas been deprecated, in favor of configuring theDefaultHttpClientdirectly.com.auth0.client.mgmt.ManagementAPIconstructors have been deprecated in favor ofManagementAPI#newBuilder(String domain, String apiToken).com.auth0.client.auth.AuthAPIconstructors have been deprecated in favor ofAuthAPI.newBuilder(String domain, String clientId)andAuthAPI.newBuilder(String domain, String clientId, String clientSecret).