From 669c6c5f1c10b8f1ad2ee48ffb4bc0ad412c4930 Mon Sep 17 00:00:00 2001 From: Luciano Balmaceda Date: Mon, 3 Apr 2017 14:07:03 -0300 Subject: [PATCH 1/4] add renew authentication endpoint --- README.md | 18 +++++++++ .../java/com/auth0/client/auth/AuthAPI.java | 36 ++++++++++++++++++ .../com/auth0/client/auth/AuthAPITest.java | 37 ++++++++++++++++++- 3 files changed, 90 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 37851bac..38df77c8 100644 --- a/README.md +++ b/README.md @@ -226,6 +226,24 @@ try { } ``` +### Renew Authentication + +Creates a new request to renew the authentication and get fresh new credentials using a valid Refresh Token. + +`AuthRequest renewAuth(String refreshToken)` + +Example: +```java +AuthRequest request = auth.renewAuth("nisd1h9dks1doWJOsaf"); +try { + TokenHolder holder = request.execute(); +} catch (APIException exception) { + // api error +} catch (Auth0Exception exception) { + // request error +} +``` + ## Management API diff --git a/src/main/java/com/auth0/client/auth/AuthAPI.java b/src/main/java/com/auth0/client/auth/AuthAPI.java index ae991661..bdb6e63d 100644 --- a/src/main/java/com/auth0/client/auth/AuthAPI.java +++ b/src/main/java/com/auth0/client/auth/AuthAPI.java @@ -25,6 +25,7 @@ public class AuthAPI { private static final String KEY_EMAIL = "email"; private static final String KEY_CONNECTION = "connection"; private static final String KEY_TOKEN = "token"; + private static final String KEY_REFRESH_TOKEN = "refresh_token"; private static final String PATH_OAUTH = "oauth"; private static final String PATH_TOKEN = "token"; @@ -442,6 +443,41 @@ public Request revokeToken(String refreshToken) { return request; } + + /** + * Creates a new request to renew the authentication and get fresh new credentials using a valid Refresh Token and the 'refresh_token' grant. + *
+     * {@code
+     * AuthAPI auth = new AuthAPI("me.auth0.com", "B3c6RYhk1v9SbIJcRIOwu62gIUGsnze", "2679NfkaBn62e6w5E8zNEzjr-yWfkaBne");
+     * try {
+     *      TokenHolder result = auth.renewAuth("ej2E8zNEzjrcSD2edjaE")
+     *          .execute();
+     * } catch (Auth0Exception e) {
+     *      //Something happened
+     * }
+     * }
+     * 
+ * + * @param refreshToken the refresh token to use to get fresh new credentials. + * @return a Request to configure and execute. + */ + public AuthRequest renewAuth(String refreshToken) { + Asserts.assertNotNull(refreshToken, "refresh token"); + + String url = HttpUrl.parse(baseUrl) + .newBuilder() + .addPathSegment(PATH_OAUTH) + .addPathSegment(PATH_TOKEN) + .build() + .toString(); + TokenRequest request = new TokenRequest(client, url); + request.addParameter(KEY_CLIENT_ID, clientId); + request.addParameter(KEY_CLIENT_SECRET, clientSecret); + request.addParameter(KEY_GRANT_TYPE, "refresh_token"); + request.addParameter(KEY_REFRESH_TOKEN, refreshToken); + return request; + } + /** * Creates a new request to exchange the code obtained in the /authorize call using the 'Authorization Code' grant. *
diff --git a/src/test/java/com/auth0/client/auth/AuthAPITest.java b/src/test/java/com/auth0/client/auth/AuthAPITest.java
index 49a6cf46..2612762d 100644
--- a/src/test/java/com/auth0/client/auth/AuthAPITest.java
+++ b/src/test/java/com/auth0/client/auth/AuthAPITest.java
@@ -714,7 +714,6 @@ public void shouldCreateLogInWithClientCredentialsGrantRequest() throws Exceptio
 
     //Revoke a Token
 
-
     @Test
     public void shouldThrowOnRevokeTokenWithNullToken() throws Exception {
         exception.expect(IllegalArgumentException.class);
@@ -742,4 +741,40 @@ public void shouldCreateRevokeTokenRequest() throws Exception {
         assertThat(response, is(nullValue()));
     }
 
+
+    //Renew Authentication using Refresh Token
+
+    @Test
+    public void shouldThrowOnRenewAuthWithNullRefreshToken() throws Exception {
+        exception.expect(IllegalArgumentException.class);
+        exception.expectMessage("'refresh token' cannot be null!");
+        api.renewAuth(null);
+    }
+
+    @Test
+    public void shouldCreateRenewAuthRequest() throws Exception {
+        AuthRequest request = api.renewAuth("ej2E8zNEzjrcSD2edjaE");
+        assertThat(request, is(notNullValue()));
+
+        server.jsonResponse(AUTH_TOKENS, 200);
+        TokenHolder response = request.execute();
+        RecordedRequest recordedRequest = server.takeRequest();
+
+        assertThat(recordedRequest, hasMethodAndPath("POST", "/oauth/token"));
+        assertThat(recordedRequest, hasHeader("Content-Type", "application/json"));
+
+        Map body = bodyFromRequest(recordedRequest);
+        assertThat(body, hasEntry("grant_type", (Object) "refresh_token"));
+        assertThat(body, hasEntry("client_id", (Object) CLIENT_ID));
+        assertThat(body, hasEntry("client_secret", (Object) CLIENT_SECRET));
+        assertThat(body, hasEntry("refresh_token", (Object) "ej2E8zNEzjrcSD2edjaE"));
+
+        assertThat(response, is(notNullValue()));
+        assertThat(response.getAccessToken(), not(isEmptyOrNullString()));
+        assertThat(response.getIdToken(), not(isEmptyOrNullString()));
+        assertThat(response.getRefreshToken(), not(isEmptyOrNullString()));
+        assertThat(response.getTokenType(), not(isEmptyOrNullString()));
+        assertThat(response.getExpiresIn(), is(notNullValue()));
+    }
+
 }
\ No newline at end of file

From 8d7d35b6aa8010f227b64466deea158972ef3901 Mon Sep 17 00:00:00 2001
From: Luciano Balmaceda 
Date: Thu, 27 Apr 2017 15:30:46 -0300
Subject: [PATCH 2/4] remove 'new' mentions in documentation

---
 README.md                                     | 44 +++++++++----------
 .../java/com/auth0/client/auth/AuthAPI.java   | 20 ++++-----
 .../client/auth/AuthorizeUrlBuilder.java      |  2 +-
 .../auth0/client/auth/LogoutUrlBuilder.java   |  2 +-
 .../auth0/client/mgmt/ClientGrantsEntity.java |  2 +-
 .../auth0/client/mgmt/ConnectionsEntity.java  |  2 +-
 .../client/mgmt/DeviceCredentialsEntity.java  |  2 +-
 .../com/auth0/client/mgmt/GuardianEntity.java |  2 +-
 .../com/auth0/client/mgmt/ManagementAPI.java  |  4 +-
 .../com/auth0/client/mgmt/RulesEntity.java    |  2 +-
 .../com/auth0/client/mgmt/UsersEntity.java    |  2 +-
 11 files changed, 42 insertions(+), 42 deletions(-)

diff --git a/README.md b/README.md
index 38df77c8..1315811e 100644
--- a/README.md
+++ b/README.md
@@ -36,7 +36,7 @@ The Auth0 Authentication API and User's Management API are available for Android
 
 The implementation is based on the [Authentication API Docs](https://auth0.com/docs/api/authentication).
 
-Create a new `AuthAPI` instance by providing the client data from the [dashboard](https://manage.auth0.com/#/clients).
+Create an `AuthAPI` instance by providing the client data from the [dashboard](https://manage.auth0.com/#/clients).
 
 ```java
 AuthAPI auth = new AuthAPI("{YOUR_DOMAIN}", "{YOUR_CLIENT_ID}", "{YOUR_CLIENT_SECRET}");
@@ -71,7 +71,7 @@ String url = auth.logoutUrl("https://me.auth0.com/home", true)
 ```
 
 ### UserInfo - /userinfo
-Creates a new request to get the user information associated to a given access token. This will only work if the token has been granted the `openid` scope.
+Creates a request to get the user information associated to a given access token. This will only work if the token has been granted the `openid` scope.
 
 `Request userInfo(String accessToken)`
 
@@ -89,7 +89,7 @@ try {
 ```
 
 ### Reset Password - /dbconnections/change_password
-Creates a new request to reset the user's password. This will only work for db connections.
+Creates a request to reset the user's password. This will only work for db connections.
 
 `Request resetPassword(String email, String connection)`
 
@@ -107,7 +107,7 @@ try {
 
 
 ### Sign Up - /dbconnections/signup
-Creates a new request to create a new user. Up to 10 additional Sign Up fields can be added to the request. This will only work for db connections.
+Creates a request to create a user. Up to 10 additional Sign Up fields can be added to the request. This will only work for db connections.
 
 `SignUpRequest signUp(String email, String username, String password, String connection)`
 
@@ -131,7 +131,7 @@ try {
 
 ### Exchange the Authorization Code - /oauth/token
 
-Creates a new request to exchange the `code` previously obtained by calling the /authorize endpoint. The redirect uri must be the one sent in the /authorize call.
+Creates a request to exchange the `code` previously obtained by calling the /authorize endpoint. The redirect uri must be the one sent in the /authorize call.
 
 `AuthRequest exchangeCode(String code, String redirectUri)`
 
@@ -151,7 +151,7 @@ try {
 
 ### Log In with Password - /oauth/token
 
-Creates a new request to log in the user with `username` and `password`. The connection used is the one defined as "Default Directory" in the account settings.
+Creates a request to log in the user with `username` and `password`. The connection used is the one defined as "Default Directory" in the account settings.
 
 `AuthRequest login(String emailOrUsername, String password)`
 
@@ -171,7 +171,7 @@ try {
 
 ### Log In with Password Realm - /oauth/token
 
-Creates a new request to log in the user with `username` and `password` using the Password Realm.
+Creates a request to log in the user with `username` and `password` using the Password Realm.
 
 `AuthRequest login(String emailOrUsername, String password, String realm)`
 
@@ -191,7 +191,7 @@ try {
 
 ### Request Token for Audience - /oauth/token
 
-Creates a new request to get a Token for the given Audience.
+Creates a request to get a Token for the given Audience.
 
 `AuthRequest requestToken(String audience)`
 
@@ -210,7 +210,7 @@ try {
 
 ### Revoke Refresh Token
 
-Creates a new request to revoke an existing Refresh Token.
+Creates a request to revoke an existing Refresh Token.
 
 `Request revokeToken(String refreshToken)`
 
@@ -228,7 +228,7 @@ try {
 
 ### Renew Authentication
 
-Creates a new request to renew the authentication and get fresh new credentials using a valid Refresh Token.
+Creates a request to renew the authentication and get fresh new credentials using a valid Refresh Token.
 
 `AuthRequest renewAuth(String refreshToken)`
 
@@ -249,7 +249,7 @@ try {
 
 The implementation is based on the [Management API Docs](https://auth0.com/docs/api/management/v2).
 
-Create a new `ManagementAPI` instance by providing the domain from the [client dashboard](https://manage.auth0.com/#/clients) and the API Token. Click [here](https://auth0.com/docs/api/management/v2#!/Introduction/Getting_an_API_token) for more information on how to obtain a valid API Token.
+Create a `ManagementAPI` instance by providing the domain from the [client dashboard](https://manage.auth0.com/#/clients) and the API Token. Click [here](https://auth0.com/docs/api/management/v2#!/Introduction/Getting_an_API_token) for more information on how to obtain a valid API Token.
 
 ```java
 ManagementAPI mgmt = new ManagementAPI("{YOUR_DOMAIN}", "{YOUR_API_TOKEN}");
@@ -277,7 +277,7 @@ The Management API is divided into different entities. Each of them have the lis
 
 #### List
 
-Creates a new request to list the Users. An API Token with scope `read:users` is needed. If you want the identities.access_token property to be included, you will also need the scope `read:user_idp_tokens`.
+Creates a request to list the Users. An API Token with scope `read:users` is needed. If you want the identities.access_token property to be included, you will also need the scope `read:user_idp_tokens`.
 You can pass an optional Filter to narrow the results in the response.
 
 `Request list(UserFilter filter)`
@@ -297,7 +297,7 @@ try {
 
 #### Get
 
-Creates a new request to get a User. An API Token with scope `read:users` is needed. If you want the identities.access_token property to be included, you will also need the scope `read:user_idp_tokens`.
+Creates a request to get a User. An API Token with scope `read:users` is needed. If you want the identities.access_token property to be included, you will also need the scope `read:user_idp_tokens`.
 You can pass an optional Filter to narrow the results in the response.
 
 `Request get(String userId, UserFilter filter)`
@@ -317,7 +317,7 @@ try {
 
 #### Create
 
-Creates a new request to create a new User. An API Token with scope `create:users` is needed.
+Creates a request to create a User. An API Token with scope `create:users` is needed.
 
 `Request create(User user)`
 
@@ -336,7 +336,7 @@ try {
 
 #### Delete
 
-Creates a new request to delete a User. An API Token with scope `delete:users` is needed.
+Creates a request to delete a User. An API Token with scope `delete:users` is needed.
 
 `Request delete(String userId)`
 
@@ -354,7 +354,7 @@ try {
 
 #### Update
 
-Creates a new request to update a User. An API Token with scope `update:users` is needed. If you're updating app_metadata you'll also need `update:users_app_metadata` scope.
+Creates a request to update a User. An API Token with scope `update:users` is needed. If you're updating app_metadata you'll also need `update:users_app_metadata` scope.
 
 `Request update(String userId, User user)`
 
@@ -373,7 +373,7 @@ try {
 
 #### Get Guardian Enrollments
 
-Creates a new request to list the User's Guardian Enrollments. An API Token with scope `read:users` is needed.
+Creates a request to list the User's Guardian Enrollments. An API Token with scope `read:users` is needed.
 
 `Request> getEnrollments(String userId)`
 
@@ -391,7 +391,7 @@ try {
 
 #### Get Log Events
 
-Creates a new request to list the User's Log Events. An API Token with scope `read:logs` is needed.
+Creates a request to list the User's Log Events. An API Token with scope `read:logs` is needed.
 You can pass an optional Filter to narrow the results in the response.
 
 `Request getLogEvents(String userId, LogEventFilter filter)`
@@ -412,7 +412,7 @@ try {
 
 #### Delete Multifactor Provider
 
-Creates a new request to delete the User's Multifactor Provider. An API Token with scope `update:users` is needed.
+Creates a request to delete the User's Multifactor Provider. An API Token with scope `update:users` is needed.
 
 `Request deleteMultifactorProvider(String userId, String provider)`
 
@@ -430,7 +430,7 @@ try {
 
 #### Rotate Recovery Code
 
-Creates a new request to rotate the User's Recovery Code. An API Token with scope `update:users` is needed.
+Creates a request to rotate the User's Recovery Code. An API Token with scope `update:users` is needed.
 
 `Request rotateRecoveryCode(String userId)`
 
@@ -448,7 +448,7 @@ try {
 
 #### Link Identities
 
-Creates a new request to link two User identities. An API Token with scope `update:users` is needed.
+Creates a request to link two User identities. An API Token with scope `update:users` is needed.
 
 `Request> linkIdentity(String primaryUserId, String secondaryUserId, String provider, String connectionId)`
 
@@ -466,7 +466,7 @@ try {
 
 #### Un-Link Identities
 
-Creates a new request to un-link two User identities. An API Token with scope `update:users` is needed.
+Creates a request to un-link two User identities. An API Token with scope `update:users` is needed.
 
 `Request> unlinkIdentity(String primaryUserId, String secondaryUserId, String provider)`
 
diff --git a/src/main/java/com/auth0/client/auth/AuthAPI.java b/src/main/java/com/auth0/client/auth/AuthAPI.java
index bdb6e63d..db4c2562 100644
--- a/src/main/java/com/auth0/client/auth/AuthAPI.java
+++ b/src/main/java/com/auth0/client/auth/AuthAPI.java
@@ -103,7 +103,7 @@ private String createBaseUrl(String domain) {
     }
 
     /**
-     * Creates a new instance of the {@link AuthorizeUrlBuilder} with the given redirect url.
+     * Creates an instance of the {@link AuthorizeUrlBuilder} with the given redirect url.
      * i.e.:
      * 
      * {@code
@@ -127,7 +127,7 @@ public AuthorizeUrlBuilder authorizeUrl(String redirectUri) {
     }
 
     /**
-     * Creates a new instance of the {@link LogoutUrlBuilder} with the given return-to url.
+     * Creates an instance of the {@link LogoutUrlBuilder} with the given return-to url.
      * i.e.:
      * 
      * {@code
@@ -217,7 +217,7 @@ public Request resetPassword(String email, String connection) {
     }
 
     /**
-     * Creates a new sign up request with the given credentials and database connection.
+     * Creates a sign up request with the given credentials and database connection.
      * "Requires Username" option must be turned on in the Connection's configuration first.
      * i.e.:
      * 
@@ -251,7 +251,7 @@ public SignUpRequest signUp(String email, String username, String password, Stri
     }
 
     /**
-     * Creates a new sign up request with the given credentials and database connection.
+     * Creates a sign up request with the given credentials and database connection.
      * i.e.:
      * 
      * {@code
@@ -294,7 +294,7 @@ public SignUpRequest signUp(String email, String password, String connection) {
     }
 
     /**
-     * Creates a new log in request using the 'Password' grant and the given credentials.
+     * Creates a log in request using the 'Password' grant and the given credentials.
      * i.e.:
      * 
      * {@code
@@ -333,7 +333,7 @@ public AuthRequest login(String emailOrUsername, String password) {
     }
 
     /**
-     * Creates a new log in request using the 'Password Realm' grant and the given credentials.
+     * Creates a log in request using the 'Password Realm' grant and the given credentials.
      * Default used realm and audience are defined in the "API Authorization Settings" in the account's advanced settings in the Auth0 Dashboard.
      * 
      * {@code
@@ -375,7 +375,7 @@ public AuthRequest login(String emailOrUsername, String password, String realm)
     }
 
     /**
-     * Creates a new request to get a Token for the given audience using the 'Client Credentials' grant.
+     * Creates a request to get a Token for the given audience using the 'Client Credentials' grant.
      * Default used realm is defined in the "API Authorization Settings" in the account's advanced settings in the Auth0 Dashboard.
      * 
      * {@code
@@ -411,7 +411,7 @@ public AuthRequest requestToken(String audience) {
     }
 
     /**
-     * Creates a new request to revoke an existing Refresh Token.
+     * Creates a request to revoke an existing Refresh Token.
      * 
      * {@code
      * AuthAPI auth = new AuthAPI("me.auth0.com", "B3c6RYhk1v9SbIJcRIOwu62gIUGsnze", "2679NfkaBn62e6w5E8zNEzjr-yWfkaBne");
@@ -445,7 +445,7 @@ public Request revokeToken(String refreshToken) {
 
 
     /**
-     * Creates a new request to renew the authentication and get fresh new credentials using a valid Refresh Token and the 'refresh_token' grant.
+     * Creates a request to renew the authentication and get fresh new credentials using a valid Refresh Token and the 'refresh_token' grant.
      * 
      * {@code
      * AuthAPI auth = new AuthAPI("me.auth0.com", "B3c6RYhk1v9SbIJcRIOwu62gIUGsnze", "2679NfkaBn62e6w5E8zNEzjr-yWfkaBne");
@@ -479,7 +479,7 @@ public AuthRequest renewAuth(String refreshToken) {
     }
 
     /**
-     * Creates a new request to exchange the code obtained in the /authorize call using the 'Authorization Code' grant.
+     * Creates a request to exchange the code obtained in the /authorize call using the 'Authorization Code' grant.
      * 
      * {@code
      * AuthAPI auth = new AuthAPI("me.auth0.com", "B3c6RYhk1v9SbIJcRIOwu62gIUGsnze", "2679NfkaBn62e6w5E8zNEzjr-yWfkaBne");
diff --git a/src/main/java/com/auth0/client/auth/AuthorizeUrlBuilder.java b/src/main/java/com/auth0/client/auth/AuthorizeUrlBuilder.java
index cd6a0e8b..afad86b5 100644
--- a/src/main/java/com/auth0/client/auth/AuthorizeUrlBuilder.java
+++ b/src/main/java/com/auth0/client/auth/AuthorizeUrlBuilder.java
@@ -18,7 +18,7 @@ public class AuthorizeUrlBuilder {
     private final HashMap parameters;
 
     /**
-     * Creates a new instance of the {@link AuthorizeUrlBuilder} using the given domain and base parameters.
+     * Creates an instance of the {@link AuthorizeUrlBuilder} using the given domain and base parameters.
      *
      * @param domain      the domain to use for this URL. Must be a valid URL.
      * @param clientId    the client_id value to set
diff --git a/src/main/java/com/auth0/client/auth/LogoutUrlBuilder.java b/src/main/java/com/auth0/client/auth/LogoutUrlBuilder.java
index ec2e9d67..d0c802ba 100644
--- a/src/main/java/com/auth0/client/auth/LogoutUrlBuilder.java
+++ b/src/main/java/com/auth0/client/auth/LogoutUrlBuilder.java
@@ -18,7 +18,7 @@ public class LogoutUrlBuilder {
     private final HashMap parameters;
 
     /**
-     * Creates a new instance of the {@link LogoutUrlBuilder} using the given domain and base parameters.
+     * Creates a instance of the {@link LogoutUrlBuilder} using the given domain and base parameters.
      *
      * @param domain      the domain to use for this URL. Must be a valid URL.
      * @param clientId    the client_id value to set
diff --git a/src/main/java/com/auth0/client/mgmt/ClientGrantsEntity.java b/src/main/java/com/auth0/client/mgmt/ClientGrantsEntity.java
index 90e1cbb2..53569226 100644
--- a/src/main/java/com/auth0/client/mgmt/ClientGrantsEntity.java
+++ b/src/main/java/com/auth0/client/mgmt/ClientGrantsEntity.java
@@ -40,7 +40,7 @@ public Request> list() {
     }
 
     /**
-     * Create a new Client Grant. A token with scope create:client_grants is needed.
+     * Create a Client Grant. A token with scope create:client_grants is needed.
      * See https://auth0.com/docs/api/management/v2#!/Client_Grants/post_client_grants
      *
      * @param clientId the client id to associate this grant with.
diff --git a/src/main/java/com/auth0/client/mgmt/ConnectionsEntity.java b/src/main/java/com/auth0/client/mgmt/ConnectionsEntity.java
index d112f71d..7e2ee860 100644
--- a/src/main/java/com/auth0/client/mgmt/ConnectionsEntity.java
+++ b/src/main/java/com/auth0/client/mgmt/ConnectionsEntity.java
@@ -74,7 +74,7 @@ public Request get(String connectionId, ConnectionFilter filter) {
     }
 
     /**
-     * Create a new Connection. A token with scope create:connections is needed.
+     * Create a Connection. A token with scope create:connections is needed.
      * See https://auth0.com/docs/api/management/v2#!/Connections/post_connections
      *
      * @param connection the connection data to set.
diff --git a/src/main/java/com/auth0/client/mgmt/DeviceCredentialsEntity.java b/src/main/java/com/auth0/client/mgmt/DeviceCredentialsEntity.java
index b15e03e2..1b5ad241 100644
--- a/src/main/java/com/auth0/client/mgmt/DeviceCredentialsEntity.java
+++ b/src/main/java/com/auth0/client/mgmt/DeviceCredentialsEntity.java
@@ -47,7 +47,7 @@ public Request> list(DeviceCredentialsFilter filter) {
     }
 
     /**
-     * Create a new Device Credentials. A token with scope create:current_user_device_credentials is needed.
+     * Create a Device Credentials. A token with scope create:current_user_device_credentials is needed.
      * See https://auth0.com/docs/api/management/v2#!/Device_Credentials/post_device_credentials
      *
      * @param deviceCredentials the device credentials data to set.
diff --git a/src/main/java/com/auth0/client/mgmt/GuardianEntity.java b/src/main/java/com/auth0/client/mgmt/GuardianEntity.java
index c948da11..cbc9c550 100644
--- a/src/main/java/com/auth0/client/mgmt/GuardianEntity.java
+++ b/src/main/java/com/auth0/client/mgmt/GuardianEntity.java
@@ -22,7 +22,7 @@ public class GuardianEntity extends BaseManagementEntity {
     }
 
     /**
-     * Create a new Guardian Enrollment Ticket. A token with scope create:guardian_enrollment_tickets is needed.
+     * Create a Guardian Enrollment Ticket. A token with scope create:guardian_enrollment_tickets is needed.
      *
      * @param enrollmentTicket the enrollment ticket data to set.
      * @return a Request to execute.
diff --git a/src/main/java/com/auth0/client/mgmt/ManagementAPI.java b/src/main/java/com/auth0/client/mgmt/ManagementAPI.java
index ea5cdb1e..125465b2 100644
--- a/src/main/java/com/auth0/client/mgmt/ManagementAPI.java
+++ b/src/main/java/com/auth0/client/mgmt/ManagementAPI.java
@@ -9,7 +9,7 @@
 
 /**
  * Class that provides an implementation of the Management API methods defined in https://auth0.com/docs/api/management/v2.
- * To begin create a new instance of {@link #ManagementAPI(String, String)} using the tenant domain and API token.
+ * To begin create an instance of {@link #ManagementAPI(String, String)} using the tenant domain and API token.
  */
 @SuppressWarnings("WeakerAccess")
 public class ManagementAPI {
@@ -21,7 +21,7 @@ public class ManagementAPI {
     private final HttpLoggingInterceptor logging;
 
     /**
-     * Create a new instance with the given tenant's domain and API token.
+     * Create an instance with the given tenant's domain and API token.
      *
      * @param domain   the tenant's domain.
      * @param apiToken the token to authenticate the calls with. See the "Getting an API token" section to learn how to obtain a token.
diff --git a/src/main/java/com/auth0/client/mgmt/RulesEntity.java b/src/main/java/com/auth0/client/mgmt/RulesEntity.java
index af16e621..93e1ae87 100644
--- a/src/main/java/com/auth0/client/mgmt/RulesEntity.java
+++ b/src/main/java/com/auth0/client/mgmt/RulesEntity.java
@@ -74,7 +74,7 @@ public Request get(String ruleId, RulesFilter filter) {
     }
 
     /**
-     * Create a new Rule. A token with scope create:rules is needed.
+     * Create a Rule. A token with scope create:rules is needed.
      * See https://auth0.com/docs/api/management/v2#!/Rules/post_rules
      *
      * @param rule the rule data to set
diff --git a/src/main/java/com/auth0/client/mgmt/UsersEntity.java b/src/main/java/com/auth0/client/mgmt/UsersEntity.java
index 890c77cc..d3afd120 100644
--- a/src/main/java/com/auth0/client/mgmt/UsersEntity.java
+++ b/src/main/java/com/auth0/client/mgmt/UsersEntity.java
@@ -83,7 +83,7 @@ public Request get(String userId, UserFilter filter) {
     }
 
     /**
-     * Create a new User. A token with scope create:users is needed.
+     * Create a User. A token with scope create:users is needed.
      * See https://auth0.com/docs/api/management/v2#!/Users/post_users
      *
      * @param user the user data to set

From e740d3244db13179509001192a94f5e08ab1239a Mon Sep 17 00:00:00 2001
From: Luciano Balmaceda 
Date: Thu, 27 Apr 2017 15:38:00 -0300
Subject: [PATCH 3/4] create a single HttpUrl instance in AuthAPI

---
 .../java/com/auth0/client/auth/AuthAPI.java   | 20 ++++++++++---------
 1 file changed, 11 insertions(+), 9 deletions(-)

diff --git a/src/main/java/com/auth0/client/auth/AuthAPI.java b/src/main/java/com/auth0/client/auth/AuthAPI.java
index db4c2562..1e9bf260 100644
--- a/src/main/java/com/auth0/client/auth/AuthAPI.java
+++ b/src/main/java/com/auth0/client/auth/AuthAPI.java
@@ -36,6 +36,7 @@ public class AuthAPI {
     private final String clientId;
     private final String clientSecret;
     private final String baseUrl;
+    private final HttpUrl httpUrl;
     private final TelemetryInterceptor telemetry;
     private final HttpLoggingInterceptor logging;
 
@@ -55,6 +56,7 @@ public AuthAPI(String domain, String clientId, String clientSecret) {
         if (baseUrl == null) {
             throw new IllegalArgumentException("The domain had an invalid format and couldn't be parsed as an URL.");
         }
+        this.httpUrl = HttpUrl.parse(baseUrl);
         this.clientId = clientId;
         this.clientSecret = clientSecret;
 
@@ -169,7 +171,7 @@ public LogoutUrlBuilder logoutUrl(String returnToUrl, boolean setClientId) {
     public Request userInfo(String accessToken) {
         Asserts.assertNotNull(accessToken, "access token");
 
-        String url = HttpUrl.parse(baseUrl)
+        String url = httpUrl
                 .newBuilder()
                 .addPathSegment("userinfo")
                 .build()
@@ -203,7 +205,7 @@ public Request resetPassword(String email, String connection) {
         Asserts.assertNotNull(email, "email");
         Asserts.assertNotNull(connection, "connection");
 
-        String url = HttpUrl.parse(baseUrl)
+        String url = httpUrl
                 .newBuilder()
                 .addPathSegment(PATH_DBCONNECTIONS)
                 .addPathSegment("change_password")
@@ -279,7 +281,7 @@ public SignUpRequest signUp(String email, String password, String connection) {
         Asserts.assertNotNull(password, "password");
         Asserts.assertNotNull(connection, "connection");
 
-        String url = HttpUrl.parse(baseUrl)
+        String url = httpUrl
                 .newBuilder()
                 .addPathSegment(PATH_DBCONNECTIONS)
                 .addPathSegment("signup")
@@ -317,7 +319,7 @@ public AuthRequest login(String emailOrUsername, String password) {
         Asserts.assertNotNull(emailOrUsername, "email or username");
         Asserts.assertNotNull(password, "password");
 
-        String url = HttpUrl.parse(baseUrl)
+        String url = httpUrl
                 .newBuilder()
                 .addPathSegment(PATH_OAUTH)
                 .addPathSegment(PATH_TOKEN)
@@ -358,7 +360,7 @@ public AuthRequest login(String emailOrUsername, String password, String realm)
         Asserts.assertNotNull(password, "password");
         Asserts.assertNotNull(realm, "realm");
 
-        String url = HttpUrl.parse(baseUrl)
+        String url = httpUrl
                 .newBuilder()
                 .addPathSegment(PATH_OAUTH)
                 .addPathSegment(PATH_TOKEN)
@@ -396,7 +398,7 @@ public AuthRequest login(String emailOrUsername, String password, String realm)
     public AuthRequest requestToken(String audience) {
         Asserts.assertNotNull(audience, "audience");
 
-        String url = HttpUrl.parse(baseUrl)
+        String url = httpUrl
                 .newBuilder()
                 .addPathSegment(PATH_OAUTH)
                 .addPathSegment(PATH_TOKEN)
@@ -430,7 +432,7 @@ public AuthRequest requestToken(String audience) {
     public Request revokeToken(String refreshToken) {
         Asserts.assertNotNull(refreshToken, "refresh token");
 
-        String url = HttpUrl.parse(baseUrl)
+        String url = httpUrl
                 .newBuilder()
                 .addPathSegment(PATH_OAUTH)
                 .addPathSegment(PATH_REVOKE)
@@ -464,7 +466,7 @@ public Request revokeToken(String refreshToken) {
     public AuthRequest renewAuth(String refreshToken) {
         Asserts.assertNotNull(refreshToken, "refresh token");
 
-        String url = HttpUrl.parse(baseUrl)
+        String url = httpUrl
                 .newBuilder()
                 .addPathSegment(PATH_OAUTH)
                 .addPathSegment(PATH_TOKEN)
@@ -501,7 +503,7 @@ public AuthRequest exchangeCode(String code, String redirectUri) {
         Asserts.assertNotNull(code, "code");
         Asserts.assertNotNull(redirectUri, "redirect uri");
 
-        String url = HttpUrl.parse(baseUrl)
+        String url = httpUrl
                 .newBuilder()
                 .addPathSegment(PATH_OAUTH)
                 .addPathSegment(PATH_TOKEN)

From 9d56b3816f6c96e332ba45f05bdaab7688de31fc Mon Sep 17 00:00:00 2001
From: Luciano Balmaceda 
Date: Thu, 27 Apr 2017 16:23:51 -0300
Subject: [PATCH 4/4] migrate baseUrl to HttpUrl (internal)

---
 .../java/com/auth0/client/auth/AuthAPI.java   | 35 +++++++++----------
 .../client/auth/AuthorizeUrlBuilder.java      | 13 ++++---
 .../auth0/client/auth/LogoutUrlBuilder.java   | 13 ++++---
 .../client/mgmt/BaseManagementEntity.java     |  4 +--
 .../auth0/client/mgmt/BlacklistsEntity.java   |  2 +-
 .../auth0/client/mgmt/ClientGrantsEntity.java |  2 +-
 .../com/auth0/client/mgmt/ClientsEntity.java  |  2 +-
 .../auth0/client/mgmt/ConnectionsEntity.java  |  2 +-
 .../client/mgmt/DeviceCredentialsEntity.java  |  2 +-
 .../client/mgmt/EmailProviderEntity.java      |  2 +-
 .../com/auth0/client/mgmt/GuardianEntity.java |  2 +-
 .../auth0/client/mgmt/LogEventsEntity.java    |  2 +-
 .../com/auth0/client/mgmt/ManagementAPI.java  | 11 +++---
 .../com/auth0/client/mgmt/RulesEntity.java    |  2 +-
 .../com/auth0/client/mgmt/StatsEntity.java    |  2 +-
 .../com/auth0/client/mgmt/TenantsEntity.java  |  2 +-
 .../com/auth0/client/mgmt/TicketsEntity.java  |  2 +-
 .../auth0/client/mgmt/UserBlocksEntity.java   |  2 +-
 .../com/auth0/client/mgmt/UsersEntity.java    |  2 +-
 .../com/auth0/client/auth/AuthAPITest.java    | 24 ++++++++++---
 .../client/auth/AuthorizeUrlBuilderTest.java  | 27 +++++---------
 .../client/auth/LogoutUrlBuilderTest.java     | 27 +++++---------
 .../auth0/client/mgmt/ManagementAPITest.java  |  6 ++--
 23 files changed, 89 insertions(+), 99 deletions(-)

diff --git a/src/main/java/com/auth0/client/auth/AuthAPI.java b/src/main/java/com/auth0/client/auth/AuthAPI.java
index 1e9bf260..560352e3 100644
--- a/src/main/java/com/auth0/client/auth/AuthAPI.java
+++ b/src/main/java/com/auth0/client/auth/AuthAPI.java
@@ -35,8 +35,7 @@ public class AuthAPI {
     private final OkHttpClient client;
     private final String clientId;
     private final String clientSecret;
-    private final String baseUrl;
-    private final HttpUrl httpUrl;
+    private final HttpUrl baseUrl;
     private final TelemetryInterceptor telemetry;
     private final HttpLoggingInterceptor logging;
 
@@ -52,11 +51,10 @@ public AuthAPI(String domain, String clientId, String clientSecret) {
         Asserts.assertNotNull(clientId, "client id");
         Asserts.assertNotNull(clientSecret, "client secret");
 
-        baseUrl = createBaseUrl(domain);
+        this.baseUrl = createBaseUrl(domain);
         if (baseUrl == null) {
             throw new IllegalArgumentException("The domain had an invalid format and couldn't be parsed as an URL.");
         }
-        this.httpUrl = HttpUrl.parse(baseUrl);
         this.clientId = clientId;
         this.clientSecret = clientSecret;
 
@@ -91,17 +89,16 @@ OkHttpClient getClient() {
     }
 
     //Visible for Testing
-    String getBaseUrl() {
+    HttpUrl getBaseUrl() {
         return baseUrl;
     }
 
-    private String createBaseUrl(String domain) {
+    private HttpUrl createBaseUrl(String domain) {
         String url = domain;
         if (!domain.startsWith("https://") && !domain.startsWith("http://")) {
             url = "https://" + domain;
         }
-        HttpUrl baseUrl = HttpUrl.parse(url);
-        return baseUrl == null ? null : baseUrl.newBuilder().build().toString();
+        return HttpUrl.parse(url);
     }
 
     /**
@@ -123,7 +120,7 @@ private String createBaseUrl(String domain) {
      * @return a new instance of the {@link AuthorizeUrlBuilder} to configure.
      */
     public AuthorizeUrlBuilder authorizeUrl(String redirectUri) {
-        Asserts.assertNotNull(redirectUri, "redirect uri");
+        Asserts.assertValidUrl(redirectUri, "redirect uri");
 
         return AuthorizeUrlBuilder.newInstance(baseUrl, clientId, redirectUri);
     }
@@ -145,7 +142,7 @@ public AuthorizeUrlBuilder authorizeUrl(String redirectUri) {
      * @return a new instance of the {@link LogoutUrlBuilder} to configure.
      */
     public LogoutUrlBuilder logoutUrl(String returnToUrl, boolean setClientId) {
-        Asserts.assertNotNull(returnToUrl, "return to url");
+        Asserts.assertValidUrl(returnToUrl, "return to url");
 
         return LogoutUrlBuilder.newInstance(baseUrl, clientId, returnToUrl, setClientId);
     }
@@ -171,7 +168,7 @@ public LogoutUrlBuilder logoutUrl(String returnToUrl, boolean setClientId) {
     public Request userInfo(String accessToken) {
         Asserts.assertNotNull(accessToken, "access token");
 
-        String url = httpUrl
+        String url = baseUrl
                 .newBuilder()
                 .addPathSegment("userinfo")
                 .build()
@@ -205,7 +202,7 @@ public Request resetPassword(String email, String connection) {
         Asserts.assertNotNull(email, "email");
         Asserts.assertNotNull(connection, "connection");
 
-        String url = httpUrl
+        String url = baseUrl
                 .newBuilder()
                 .addPathSegment(PATH_DBCONNECTIONS)
                 .addPathSegment("change_password")
@@ -281,7 +278,7 @@ public SignUpRequest signUp(String email, String password, String connection) {
         Asserts.assertNotNull(password, "password");
         Asserts.assertNotNull(connection, "connection");
 
-        String url = httpUrl
+        String url = baseUrl
                 .newBuilder()
                 .addPathSegment(PATH_DBCONNECTIONS)
                 .addPathSegment("signup")
@@ -319,7 +316,7 @@ public AuthRequest login(String emailOrUsername, String password) {
         Asserts.assertNotNull(emailOrUsername, "email or username");
         Asserts.assertNotNull(password, "password");
 
-        String url = httpUrl
+        String url = baseUrl
                 .newBuilder()
                 .addPathSegment(PATH_OAUTH)
                 .addPathSegment(PATH_TOKEN)
@@ -360,7 +357,7 @@ public AuthRequest login(String emailOrUsername, String password, String realm)
         Asserts.assertNotNull(password, "password");
         Asserts.assertNotNull(realm, "realm");
 
-        String url = httpUrl
+        String url = baseUrl
                 .newBuilder()
                 .addPathSegment(PATH_OAUTH)
                 .addPathSegment(PATH_TOKEN)
@@ -398,7 +395,7 @@ public AuthRequest login(String emailOrUsername, String password, String realm)
     public AuthRequest requestToken(String audience) {
         Asserts.assertNotNull(audience, "audience");
 
-        String url = httpUrl
+        String url = baseUrl
                 .newBuilder()
                 .addPathSegment(PATH_OAUTH)
                 .addPathSegment(PATH_TOKEN)
@@ -432,7 +429,7 @@ public AuthRequest requestToken(String audience) {
     public Request revokeToken(String refreshToken) {
         Asserts.assertNotNull(refreshToken, "refresh token");
 
-        String url = httpUrl
+        String url = baseUrl
                 .newBuilder()
                 .addPathSegment(PATH_OAUTH)
                 .addPathSegment(PATH_REVOKE)
@@ -466,7 +463,7 @@ public Request revokeToken(String refreshToken) {
     public AuthRequest renewAuth(String refreshToken) {
         Asserts.assertNotNull(refreshToken, "refresh token");
 
-        String url = httpUrl
+        String url = baseUrl
                 .newBuilder()
                 .addPathSegment(PATH_OAUTH)
                 .addPathSegment(PATH_TOKEN)
@@ -503,7 +500,7 @@ public AuthRequest exchangeCode(String code, String redirectUri) {
         Asserts.assertNotNull(code, "code");
         Asserts.assertNotNull(redirectUri, "redirect uri");
 
-        String url = httpUrl
+        String url = baseUrl
                 .newBuilder()
                 .addPathSegment(PATH_OAUTH)
                 .addPathSegment(PATH_TOKEN)
diff --git a/src/main/java/com/auth0/client/auth/AuthorizeUrlBuilder.java b/src/main/java/com/auth0/client/auth/AuthorizeUrlBuilder.java
index afad86b5..d1ede3c9 100644
--- a/src/main/java/com/auth0/client/auth/AuthorizeUrlBuilder.java
+++ b/src/main/java/com/auth0/client/auth/AuthorizeUrlBuilder.java
@@ -6,7 +6,6 @@
 import java.util.Map;
 
 import static com.auth0.utils.Asserts.assertNotNull;
-import static com.auth0.utils.Asserts.assertValidUrl;
 
 /**
  * Class that provides the methods to generate a valid Auth0 Authorize Url. It's based on the https://auth0.com/docs/api/authentication#social docs.
@@ -20,22 +19,22 @@ public class AuthorizeUrlBuilder {
     /**
      * Creates an instance of the {@link AuthorizeUrlBuilder} using the given domain and base parameters.
      *
-     * @param domain      the domain to use for this URL. Must be a valid URL.
+     * @param baseUrl         the base url constructed from a valid domain.
      * @param clientId    the client_id value to set
      * @param redirectUri the redirect_uri value to set. Must be already URL Encoded and must be white-listed in your Auth0's dashboard.
      * @return a new instance of the {@link AuthorizeUrlBuilder} to configure.
      */
-    static AuthorizeUrlBuilder newInstance(String domain, String clientId, String redirectUri) {
-        return new AuthorizeUrlBuilder(domain, clientId, redirectUri);
+    static AuthorizeUrlBuilder newInstance(HttpUrl baseUrl, String clientId, String redirectUri) {
+        return new AuthorizeUrlBuilder(baseUrl, clientId, redirectUri);
     }
 
-    private AuthorizeUrlBuilder(String domain, String clientId, String redirectUri) {
-        assertValidUrl(domain, "domain");
+    private AuthorizeUrlBuilder(HttpUrl url, String clientId, String redirectUri) {
+        assertNotNull(url, "base url");
         assertNotNull(clientId, "client id");
         assertNotNull(redirectUri, "redirect uri");
 
         parameters = new HashMap<>();
-        builder = HttpUrl.parse(domain).newBuilder()
+        builder = url.newBuilder()
                 .addPathSegment("authorize")
                 .addEncodedQueryParameter("redirect_uri", redirectUri)
                 .addQueryParameter("client_id", clientId);
diff --git a/src/main/java/com/auth0/client/auth/LogoutUrlBuilder.java b/src/main/java/com/auth0/client/auth/LogoutUrlBuilder.java
index d0c802ba..e383b7f2 100644
--- a/src/main/java/com/auth0/client/auth/LogoutUrlBuilder.java
+++ b/src/main/java/com/auth0/client/auth/LogoutUrlBuilder.java
@@ -6,7 +6,6 @@
 import java.util.Map;
 
 import static com.auth0.utils.Asserts.assertNotNull;
-import static com.auth0.utils.Asserts.assertValidUrl;
 
 /**
  * Class that provides the methods to generate a valid Auth0 Logout Url. It's based on the https://auth0.com/docs/api/authentication#logout docs.
@@ -20,22 +19,22 @@ public class LogoutUrlBuilder {
     /**
      * Creates a instance of the {@link LogoutUrlBuilder} using the given domain and base parameters.
      *
-     * @param domain      the domain to use for this URL. Must be a valid URL.
+     * @param baseUrl     the base url constructed from a valid domain.
      * @param clientId    the client_id value to set
      * @param returnToUrl the returnTo value to set. Must be already URL Encoded and must be white-listed in your Auth0's dashboard.
      * @param setClientId whether the client_id value must be set or not. This affects the white-list that the Auth0's Dashboard uses to validate the returnTo url.
      * @return a new instance of the {@link LogoutUrlBuilder} to configure.
      */
-    static LogoutUrlBuilder newInstance(String domain, String clientId, String returnToUrl, boolean setClientId) {
-        return new LogoutUrlBuilder(domain, setClientId ? clientId : null, returnToUrl);
+    static LogoutUrlBuilder newInstance(HttpUrl baseUrl, String clientId, String returnToUrl, boolean setClientId) {
+        return new LogoutUrlBuilder(baseUrl, setClientId ? clientId : null, returnToUrl);
     }
 
-    private LogoutUrlBuilder(String domain, String clientId, String returnToUrl) {
-        assertValidUrl(domain, "domain");
+    private LogoutUrlBuilder(HttpUrl url, String clientId, String returnToUrl) {
+        assertNotNull(url, "base url");
         assertNotNull(returnToUrl, "return to url");
 
         parameters = new HashMap<>();
-        builder = HttpUrl.parse(domain).newBuilder()
+        builder = url.newBuilder()
                 .addPathSegment("v2")
                 .addPathSegment("logout")
                 .addEncodedQueryParameter("returnTo", returnToUrl);
diff --git a/src/main/java/com/auth0/client/mgmt/BaseManagementEntity.java b/src/main/java/com/auth0/client/mgmt/BaseManagementEntity.java
index 15747a1d..0e4000b1 100644
--- a/src/main/java/com/auth0/client/mgmt/BaseManagementEntity.java
+++ b/src/main/java/com/auth0/client/mgmt/BaseManagementEntity.java
@@ -8,9 +8,9 @@ abstract class BaseManagementEntity {
     protected final HttpUrl baseUrl;
     protected final String apiToken;
 
-    BaseManagementEntity(OkHttpClient client, String baseUrl, String apiToken) {
+    BaseManagementEntity(OkHttpClient client, HttpUrl baseUrl, String apiToken) {
         this.client = client;
-        this.baseUrl = HttpUrl.parse(baseUrl);
+        this.baseUrl = baseUrl;
         this.apiToken = apiToken;
     }
 }
diff --git a/src/main/java/com/auth0/client/mgmt/BlacklistsEntity.java b/src/main/java/com/auth0/client/mgmt/BlacklistsEntity.java
index 5d521222..93814f01 100644
--- a/src/main/java/com/auth0/client/mgmt/BlacklistsEntity.java
+++ b/src/main/java/com/auth0/client/mgmt/BlacklistsEntity.java
@@ -17,7 +17,7 @@
 @SuppressWarnings("WeakerAccess")
 public class BlacklistsEntity extends BaseManagementEntity {
 
-    BlacklistsEntity(OkHttpClient client, String baseUrl, String apiToken) {
+    BlacklistsEntity(OkHttpClient client, HttpUrl baseUrl, String apiToken) {
         super(client, baseUrl, apiToken);
     }
 
diff --git a/src/main/java/com/auth0/client/mgmt/ClientGrantsEntity.java b/src/main/java/com/auth0/client/mgmt/ClientGrantsEntity.java
index 53569226..80287eda 100644
--- a/src/main/java/com/auth0/client/mgmt/ClientGrantsEntity.java
+++ b/src/main/java/com/auth0/client/mgmt/ClientGrantsEntity.java
@@ -17,7 +17,7 @@
 @SuppressWarnings("WeakerAccess")
 public class ClientGrantsEntity extends BaseManagementEntity {
 
-    ClientGrantsEntity(OkHttpClient client, String baseUrl, String apiToken) {
+    ClientGrantsEntity(OkHttpClient client, HttpUrl baseUrl, String apiToken) {
         super(client, baseUrl, apiToken);
     }
 
diff --git a/src/main/java/com/auth0/client/mgmt/ClientsEntity.java b/src/main/java/com/auth0/client/mgmt/ClientsEntity.java
index afd16fe7..9b3d524a 100644
--- a/src/main/java/com/auth0/client/mgmt/ClientsEntity.java
+++ b/src/main/java/com/auth0/client/mgmt/ClientsEntity.java
@@ -18,7 +18,7 @@
 @SuppressWarnings("WeakerAccess")
 public class ClientsEntity extends BaseManagementEntity {
 
-    ClientsEntity(OkHttpClient client, String baseUrl, String apiToken) {
+    ClientsEntity(OkHttpClient client, HttpUrl baseUrl, String apiToken) {
         super(client, baseUrl, apiToken);
     }
 
diff --git a/src/main/java/com/auth0/client/mgmt/ConnectionsEntity.java b/src/main/java/com/auth0/client/mgmt/ConnectionsEntity.java
index 7e2ee860..3566c758 100644
--- a/src/main/java/com/auth0/client/mgmt/ConnectionsEntity.java
+++ b/src/main/java/com/auth0/client/mgmt/ConnectionsEntity.java
@@ -19,7 +19,7 @@
 @SuppressWarnings("WeakerAccess")
 public class ConnectionsEntity extends BaseManagementEntity {
 
-    ConnectionsEntity(OkHttpClient client, String baseUrl, String apiToken) {
+    ConnectionsEntity(OkHttpClient client, HttpUrl baseUrl, String apiToken) {
         super(client, baseUrl, apiToken);
     }
 
diff --git a/src/main/java/com/auth0/client/mgmt/DeviceCredentialsEntity.java b/src/main/java/com/auth0/client/mgmt/DeviceCredentialsEntity.java
index 1b5ad241..4ca82265 100644
--- a/src/main/java/com/auth0/client/mgmt/DeviceCredentialsEntity.java
+++ b/src/main/java/com/auth0/client/mgmt/DeviceCredentialsEntity.java
@@ -19,7 +19,7 @@
 @SuppressWarnings("WeakerAccess")
 public class DeviceCredentialsEntity extends BaseManagementEntity {
 
-    DeviceCredentialsEntity(OkHttpClient client, String baseUrl, String apiToken) {
+    DeviceCredentialsEntity(OkHttpClient client, HttpUrl baseUrl, String apiToken) {
         super(client, baseUrl, apiToken);
     }
 
diff --git a/src/main/java/com/auth0/client/mgmt/EmailProviderEntity.java b/src/main/java/com/auth0/client/mgmt/EmailProviderEntity.java
index 3cc5dc6d..439c222b 100644
--- a/src/main/java/com/auth0/client/mgmt/EmailProviderEntity.java
+++ b/src/main/java/com/auth0/client/mgmt/EmailProviderEntity.java
@@ -17,7 +17,7 @@
  */
 @SuppressWarnings("WeakerAccess")
 public class EmailProviderEntity extends BaseManagementEntity {
-    EmailProviderEntity(OkHttpClient client, String baseUrl, String apiToken) {
+    EmailProviderEntity(OkHttpClient client, HttpUrl baseUrl, String apiToken) {
         super(client, baseUrl, apiToken);
     }
 
diff --git a/src/main/java/com/auth0/client/mgmt/GuardianEntity.java b/src/main/java/com/auth0/client/mgmt/GuardianEntity.java
index cbc9c550..baa29b70 100644
--- a/src/main/java/com/auth0/client/mgmt/GuardianEntity.java
+++ b/src/main/java/com/auth0/client/mgmt/GuardianEntity.java
@@ -17,7 +17,7 @@
 @SuppressWarnings("WeakerAccess")
 public class GuardianEntity extends BaseManagementEntity {
 
-    GuardianEntity(OkHttpClient client, String baseUrl, String apiToken) {
+    GuardianEntity(OkHttpClient client, HttpUrl baseUrl, String apiToken) {
         super(client, baseUrl, apiToken);
     }
 
diff --git a/src/main/java/com/auth0/client/mgmt/LogEventsEntity.java b/src/main/java/com/auth0/client/mgmt/LogEventsEntity.java
index 8e77d40b..7efc2b10 100644
--- a/src/main/java/com/auth0/client/mgmt/LogEventsEntity.java
+++ b/src/main/java/com/auth0/client/mgmt/LogEventsEntity.java
@@ -18,7 +18,7 @@
 @SuppressWarnings("WeakerAccess")
 public class LogEventsEntity extends BaseManagementEntity {
 
-    LogEventsEntity(OkHttpClient client, String baseUrl, String apiToken) {
+    LogEventsEntity(OkHttpClient client, HttpUrl baseUrl, String apiToken) {
         super(client, baseUrl, apiToken);
     }
 
diff --git a/src/main/java/com/auth0/client/mgmt/ManagementAPI.java b/src/main/java/com/auth0/client/mgmt/ManagementAPI.java
index 125465b2..f6825554 100644
--- a/src/main/java/com/auth0/client/mgmt/ManagementAPI.java
+++ b/src/main/java/com/auth0/client/mgmt/ManagementAPI.java
@@ -14,7 +14,7 @@
 @SuppressWarnings("WeakerAccess")
 public class ManagementAPI {
 
-    private final String baseUrl;
+    private final HttpUrl baseUrl;
     private final String apiToken;
     private final OkHttpClient client;
     private final TelemetryInterceptor telemetry;
@@ -30,7 +30,7 @@ public ManagementAPI(String domain, String apiToken) {
         Asserts.assertNotNull(domain, "domain");
         Asserts.assertNotNull(apiToken, "api token");
 
-        baseUrl = createBaseUrl(domain);
+        this.baseUrl = createBaseUrl(domain);
         if (baseUrl == null) {
             throw new IllegalArgumentException("The domain had an invalid format and couldn't be parsed as an URL.");
         }
@@ -67,17 +67,16 @@ OkHttpClient getClient() {
     }
 
     //Visible for testing
-    String getBaseUrl() {
+    HttpUrl getBaseUrl() {
         return baseUrl;
     }
 
-    private String createBaseUrl(String domain) {
+    private HttpUrl createBaseUrl(String domain) {
         String url = domain;
         if (!domain.startsWith("https://") && !domain.startsWith("http://")) {
             url = "https://" + domain;
         }
-        HttpUrl baseUrl = HttpUrl.parse(url);
-        return baseUrl == null ? null : baseUrl.newBuilder().build().toString();
+        return HttpUrl.parse(url);
     }
 
     /**
diff --git a/src/main/java/com/auth0/client/mgmt/RulesEntity.java b/src/main/java/com/auth0/client/mgmt/RulesEntity.java
index 93e1ae87..01b08620 100644
--- a/src/main/java/com/auth0/client/mgmt/RulesEntity.java
+++ b/src/main/java/com/auth0/client/mgmt/RulesEntity.java
@@ -19,7 +19,7 @@
 @SuppressWarnings("WeakerAccess")
 public class RulesEntity extends BaseManagementEntity {
 
-    RulesEntity(OkHttpClient client, String baseUrl, String apiToken) {
+    RulesEntity(OkHttpClient client, HttpUrl baseUrl, String apiToken) {
         super(client, baseUrl, apiToken);
     }
 
diff --git a/src/main/java/com/auth0/client/mgmt/StatsEntity.java b/src/main/java/com/auth0/client/mgmt/StatsEntity.java
index 7877e712..fb029ef3 100644
--- a/src/main/java/com/auth0/client/mgmt/StatsEntity.java
+++ b/src/main/java/com/auth0/client/mgmt/StatsEntity.java
@@ -18,7 +18,7 @@
 @SuppressWarnings("WeakerAccess")
 public class StatsEntity extends BaseManagementEntity {
 
-    StatsEntity(OkHttpClient client, String baseUrl, String apiToken) {
+    StatsEntity(OkHttpClient client, HttpUrl baseUrl, String apiToken) {
         super(client, baseUrl, apiToken);
     }
 
diff --git a/src/main/java/com/auth0/client/mgmt/TenantsEntity.java b/src/main/java/com/auth0/client/mgmt/TenantsEntity.java
index 2896e9bf..03b72f87 100644
--- a/src/main/java/com/auth0/client/mgmt/TenantsEntity.java
+++ b/src/main/java/com/auth0/client/mgmt/TenantsEntity.java
@@ -17,7 +17,7 @@
 @SuppressWarnings("WeakerAccess")
 public class TenantsEntity extends BaseManagementEntity {
 
-    TenantsEntity(OkHttpClient client, String baseUrl, String apiToken) {
+    TenantsEntity(OkHttpClient client, HttpUrl baseUrl, String apiToken) {
         super(client, baseUrl, apiToken);
     }
 
diff --git a/src/main/java/com/auth0/client/mgmt/TicketsEntity.java b/src/main/java/com/auth0/client/mgmt/TicketsEntity.java
index 275857a0..ae7b63fa 100644
--- a/src/main/java/com/auth0/client/mgmt/TicketsEntity.java
+++ b/src/main/java/com/auth0/client/mgmt/TicketsEntity.java
@@ -15,7 +15,7 @@
 @SuppressWarnings("WeakerAccess")
 public class TicketsEntity extends BaseManagementEntity {
 
-    TicketsEntity(OkHttpClient client, String baseUrl, String apiToken) {
+    TicketsEntity(OkHttpClient client, HttpUrl baseUrl, String apiToken) {
         super(client, baseUrl, apiToken);
     }
 
diff --git a/src/main/java/com/auth0/client/mgmt/UserBlocksEntity.java b/src/main/java/com/auth0/client/mgmt/UserBlocksEntity.java
index e314e4ea..70377416 100644
--- a/src/main/java/com/auth0/client/mgmt/UserBlocksEntity.java
+++ b/src/main/java/com/auth0/client/mgmt/UserBlocksEntity.java
@@ -15,7 +15,7 @@
 @SuppressWarnings("WeakerAccess")
 public class UserBlocksEntity extends BaseManagementEntity {
 
-    UserBlocksEntity(OkHttpClient client, String baseUrl, String apiToken) {
+    UserBlocksEntity(OkHttpClient client, HttpUrl baseUrl, String apiToken) {
         super(client, baseUrl, apiToken);
     }
 
diff --git a/src/main/java/com/auth0/client/mgmt/UsersEntity.java b/src/main/java/com/auth0/client/mgmt/UsersEntity.java
index d3afd120..bc23d43e 100644
--- a/src/main/java/com/auth0/client/mgmt/UsersEntity.java
+++ b/src/main/java/com/auth0/client/mgmt/UsersEntity.java
@@ -26,7 +26,7 @@
 @SuppressWarnings("WeakerAccess")
 public class UsersEntity extends BaseManagementEntity {
 
-    UsersEntity(OkHttpClient client, String baseUrl, String apiToken) {
+    UsersEntity(OkHttpClient client, HttpUrl baseUrl, String apiToken) {
         super(client, baseUrl, apiToken);
     }
 
diff --git a/src/test/java/com/auth0/client/auth/AuthAPITest.java b/src/test/java/com/auth0/client/auth/AuthAPITest.java
index 2612762d..5dfae3a1 100644
--- a/src/test/java/com/auth0/client/auth/AuthAPITest.java
+++ b/src/test/java/com/auth0/client/auth/AuthAPITest.java
@@ -59,14 +59,16 @@ public void tearDown() throws Exception {
     public void shouldAcceptDomainWithNoScheme() throws Exception {
         AuthAPI api = new AuthAPI("me.something.com", CLIENT_ID, CLIENT_SECRET);
 
-        assertThat(api.getBaseUrl(), isUrl("https", "me.something.com"));
+        assertThat(api.getBaseUrl(), is(notNullValue()));
+        assertThat(api.getBaseUrl().toString(), isUrl("https", "me.something.com"));
     }
 
     @Test
     public void shouldAcceptDomainWithHttpScheme() throws Exception {
         AuthAPI api = new AuthAPI("http://me.something.com", CLIENT_ID, CLIENT_SECRET);
 
-        assertThat(api.getBaseUrl(), isUrl("http", "me.something.com"));
+        assertThat(api.getBaseUrl(), is(notNullValue()));
+        assertThat(api.getBaseUrl().toString(), isUrl("http", "me.something.com"));
     }
 
     @Test
@@ -170,10 +172,17 @@ public void shouldDisableLoggingInterceptor() throws Exception {
     @Test
     public void shouldThrowWhenAuthorizeUrlBuilderRedirectUriIsNull() throws Exception {
         exception.expect(IllegalArgumentException.class);
-        exception.expectMessage("'redirect uri' cannot be null!");
+        exception.expectMessage("'redirect uri' must be a valid URL!");
         api.authorizeUrl(null);
     }
 
+    @Test
+    public void shouldThrowWhenAuthorizeUrlBuilderRedirectUriIsNotValidURL() throws Exception {
+        exception.expect(IllegalArgumentException.class);
+        exception.expectMessage("'redirect uri' must be a valid URL!");
+        api.authorizeUrl("notvalid.url");
+    }
+
     @Test
     public void shouldGetAuthorizeUrlBuilder() throws Exception {
         AuthorizeUrlBuilder builder = api.authorizeUrl("https://domain.auth0.com/callback");
@@ -198,10 +207,17 @@ public void shouldSetAuthorizeUrlBuilderDefaultValues() throws Exception {
     @Test
     public void shouldThrowWhenLogoutUrlBuilderReturnToUrlIsNull() throws Exception {
         exception.expect(IllegalArgumentException.class);
-        exception.expectMessage("'return to url' cannot be null!");
+        exception.expectMessage("'return to url' must be a valid URL!");
         api.logoutUrl(null, true);
     }
 
+    @Test
+    public void shouldThrowWhenLogoutUrlBuilderRedirectUriIsNotValidURL() throws Exception {
+        exception.expect(IllegalArgumentException.class);
+        exception.expectMessage("'return to url' must be a valid URL!");
+        api.logoutUrl("notvalid.url", true);
+    }
+
     @Test
     public void shouldGetLogoutUrlBuilder() throws Exception {
         LogoutUrlBuilder builder = api.logoutUrl("https://domain.auth0.com/callback", true);
diff --git a/src/test/java/com/auth0/client/auth/AuthorizeUrlBuilderTest.java b/src/test/java/com/auth0/client/auth/AuthorizeUrlBuilderTest.java
index fed43035..5a722385 100644
--- a/src/test/java/com/auth0/client/auth/AuthorizeUrlBuilderTest.java
+++ b/src/test/java/com/auth0/client/auth/AuthorizeUrlBuilderTest.java
@@ -1,5 +1,6 @@
 package com.auth0.client.auth;
 
+import okhttp3.HttpUrl;
 import org.junit.Rule;
 import org.junit.Test;
 import org.junit.rules.ExpectedException;
@@ -13,7 +14,7 @@
 
 public class AuthorizeUrlBuilderTest {
 
-    private static final String DOMAIN = "https://domain.auth0.com";
+    private static final HttpUrl DOMAIN = HttpUrl.parse("https://domain.auth0.com");
     private static final String CLIENT_ID = "clientId";
     private static final String REDIRECT_URI = "https://domain.auth0.com/callback";
 
@@ -21,26 +22,12 @@ public class AuthorizeUrlBuilderTest {
     public ExpectedException exception = ExpectedException.none();
 
     @Test
-    public void shouldThrowWhenDomainIsNull() throws Exception {
+    public void shouldThrowWhenBaseUrlIsNull() throws Exception {
         exception.expect(IllegalArgumentException.class);
-        exception.expectMessage("'domain' must be a valid URL!");
+        exception.expectMessage("'base url' cannot be null!");
         AuthorizeUrlBuilder.newInstance(null, CLIENT_ID, REDIRECT_URI);
     }
 
-    @Test
-    public void shouldThrowWhenDomainHasNoScheme() throws Exception {
-        exception.expect(IllegalArgumentException.class);
-        exception.expectMessage("'domain' must be a valid URL!");
-        AuthorizeUrlBuilder.newInstance("me.something.com", CLIENT_ID, REDIRECT_URI);
-    }
-
-    @Test
-    public void shouldThrowWhenDomainIsNotURL() throws Exception {
-        exception.expect(IllegalArgumentException.class);
-        exception.expectMessage("'domain' must be a valid URL!");
-        AuthorizeUrlBuilder.newInstance("something", CLIENT_ID, REDIRECT_URI);
-    }
-
     @Test
     public void shouldThrowWhenRedirectUriIsNull() throws Exception {
         exception.expect(IllegalArgumentException.class);
@@ -63,13 +50,15 @@ public void shouldGetNewInstance() throws Exception {
 
     @Test
     public void shouldBuildValidAuthorizeUrlWithHttp() throws Exception {
-        String url = AuthorizeUrlBuilder.newInstance("http://domain.auth0.com", CLIENT_ID, REDIRECT_URI).build();
+        HttpUrl httpBaseUrl = HttpUrl.parse("http://domain.auth0.com");
+        String url = AuthorizeUrlBuilder.newInstance(httpBaseUrl, CLIENT_ID, REDIRECT_URI).build();
         assertThat(url, isUrl("http", "domain.auth0.com", "/authorize"));
     }
 
     @Test
     public void shouldBuildValidAuthorizeUrlWithHttps() throws Exception {
-        String url = AuthorizeUrlBuilder.newInstance("https://domain.auth0.com", CLIENT_ID, REDIRECT_URI).build();
+        HttpUrl httpsBaseUrl = HttpUrl.parse("https://domain.auth0.com");
+        String url = AuthorizeUrlBuilder.newInstance(httpsBaseUrl, CLIENT_ID, REDIRECT_URI).build();
         assertThat(url, isUrl("https", "domain.auth0.com", "/authorize"));
     }
 
diff --git a/src/test/java/com/auth0/client/auth/LogoutUrlBuilderTest.java b/src/test/java/com/auth0/client/auth/LogoutUrlBuilderTest.java
index 7b4feefd..572007d4 100644
--- a/src/test/java/com/auth0/client/auth/LogoutUrlBuilderTest.java
+++ b/src/test/java/com/auth0/client/auth/LogoutUrlBuilderTest.java
@@ -1,5 +1,6 @@
 package com.auth0.client.auth;
 
+import okhttp3.HttpUrl;
 import org.junit.Rule;
 import org.junit.Test;
 import org.junit.rules.ExpectedException;
@@ -13,7 +14,7 @@
 
 public class LogoutUrlBuilderTest {
 
-    private static final String DOMAIN = "https://domain.auth0.com";
+    private static final HttpUrl DOMAIN = HttpUrl.parse("https://domain.auth0.com");
     private static final String CLIENT_ID = "clientId";
     private static final String RETURN_TO_URL = "https://domain.auth0.com/callback";
 
@@ -21,26 +22,12 @@ public class LogoutUrlBuilderTest {
     public ExpectedException exception = ExpectedException.none();
 
     @Test
-    public void shouldThrowWhenDomainIsNull() throws Exception {
+    public void shouldThrowWhenBaseUrlIsNull() throws Exception {
         exception.expect(IllegalArgumentException.class);
-        exception.expectMessage("'domain' must be a valid URL!");
+        exception.expectMessage("'base url' cannot be null!");
         LogoutUrlBuilder.newInstance(null, CLIENT_ID, RETURN_TO_URL, true);
     }
 
-    @Test
-    public void shouldThrowWhenDomainHasNoScheme() throws Exception {
-        exception.expect(IllegalArgumentException.class);
-        exception.expectMessage("'domain' must be a valid URL!");
-        LogoutUrlBuilder.newInstance("me.something.com", CLIENT_ID, RETURN_TO_URL, true);
-    }
-
-    @Test
-    public void shouldThrowWhenDomainIsNotURL() throws Exception {
-        exception.expect(IllegalArgumentException.class);
-        exception.expectMessage("'domain' must be a valid URL!");
-        LogoutUrlBuilder.newInstance("something", CLIENT_ID, RETURN_TO_URL, true);
-    }
-
     @Test
     public void shouldThrowWhenReturnToURLIsNull() throws Exception {
         exception.expect(IllegalArgumentException.class);
@@ -61,13 +48,15 @@ public void shouldGetNewInstance() throws Exception {
 
     @Test
     public void shouldBuildValidLogoutUrlWithHttp() throws Exception {
-        String url = LogoutUrlBuilder.newInstance("http://domain.auth0.com", CLIENT_ID, RETURN_TO_URL, true).build();
+        HttpUrl httpBaseUrl = HttpUrl.parse("http://domain.auth0.com");
+        String url = LogoutUrlBuilder.newInstance(httpBaseUrl, CLIENT_ID, RETURN_TO_URL, true).build();
         assertThat(url, isUrl("http", "domain.auth0.com", "/v2/logout"));
     }
 
     @Test
     public void shouldBuildValidLogoutUrlWithHttps() throws Exception {
-        String url = LogoutUrlBuilder.newInstance("https://domain.auth0.com", CLIENT_ID, RETURN_TO_URL, true).build();
+        HttpUrl httpsBaseUrl = HttpUrl.parse("https://domain.auth0.com");
+        String url = LogoutUrlBuilder.newInstance(httpsBaseUrl, CLIENT_ID, RETURN_TO_URL, true).build();
         assertThat(url, isUrl("https", "domain.auth0.com", "/v2/logout"));
     }
 
diff --git a/src/test/java/com/auth0/client/mgmt/ManagementAPITest.java b/src/test/java/com/auth0/client/mgmt/ManagementAPITest.java
index 6120290a..2a117b95 100644
--- a/src/test/java/com/auth0/client/mgmt/ManagementAPITest.java
+++ b/src/test/java/com/auth0/client/mgmt/ManagementAPITest.java
@@ -42,14 +42,16 @@ public void tearDown() throws Exception {
     public void shouldAcceptDomainWithNoScheme() throws Exception {
         ManagementAPI api = new ManagementAPI("me.something.com", API_TOKEN);
 
-        assertThat(api.getBaseUrl(), isUrl("https", "me.something.com"));
+        assertThat(api.getBaseUrl(), is(notNullValue()));
+        assertThat(api.getBaseUrl().toString(), isUrl("https", "me.something.com"));
     }
 
     @Test
     public void shouldAcceptDomainWithHttpScheme() throws Exception {
         ManagementAPI api = new ManagementAPI("http://me.something.com", API_TOKEN);
 
-        assertThat(api.getBaseUrl(), isUrl("http", "me.something.com"));
+        assertThat(api.getBaseUrl(), is(notNullValue()));
+        assertThat(api.getBaseUrl().toString(), isUrl("http", "me.something.com"));
     }
 
     @Test