Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 23 additions & 3 deletions src/main/java/com/auth0/client/mgmt/ManagementAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,17 @@ public static ManagementAPI.Builder newBuilder(String domain, String apiToken) {
return new ManagementAPI.Builder(domain, apiToken);
}

/**
* Instantiate a new {@link Builder} to configure and build a new ManagementAPI client.
*
* @param domain the tenant's domain. Must be a non-null valid HTTPS domain.
* @param tokenProvider the API Token provider to use when making requests.
* @return a Builder for further configuration.
*/
public static ManagementAPI.Builder newBuilder(String domain, TokenProvider tokenProvider) {
return new ManagementAPI.Builder(domain, tokenProvider);
}

private ManagementAPI(String domain, TokenProvider tokenProvider, Auth0HttpClient httpClient) {
Asserts.assertNotNull(domain, "domain");
Asserts.assertNotNull(tokenProvider, "token provider");
Expand Down Expand Up @@ -409,7 +420,7 @@ public NetworkAclsEntity networkAcls() {
*/
public static class Builder {
private final String domain;
private final String apiToken;
private final TokenProvider tokenProvider;
private Auth0HttpClient httpClient = DefaultHttpClient.newBuilder().build();

/**
Expand All @@ -418,8 +429,17 @@ public static class Builder {
* @param apiToken the API token used to make requests to the Auth0 Management API.
*/
public Builder(String domain, String apiToken) {
this(domain, SimpleTokenProvider.create(apiToken));
}

/**
* Create a new Builder
* @param domain the domain of the tenant.
* @param tokenProvider the API Token provider to use when making requests.
*/
public Builder(String domain, TokenProvider tokenProvider) {
this.domain = domain;
this.apiToken = apiToken;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have to update the build method with tokenProvider

this.tokenProvider = tokenProvider;
}

/**
Expand All @@ -438,7 +458,7 @@ public Builder withHttpClient(Auth0HttpClient httpClient) {
* @return the configured {@code ManagementAPI} instance.
*/
public ManagementAPI build() {
return new ManagementAPI(domain, SimpleTokenProvider.create(apiToken), httpClient);
return new ManagementAPI(domain, tokenProvider, httpClient);
}
}
}
10 changes: 7 additions & 3 deletions src/test/java/com/auth0/client/mgmt/ManagementAPITest.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,12 @@ public CompletableFuture<Auth0HttpResponse> sendRequestAsync(Auth0HttpRequest re
}
};

ManagementAPI api = ManagementAPI.newBuilder(DOMAIN, API_TOKEN)
.withHttpClient(httpClient).build();
ManagementAPI api = ManagementAPI.newBuilder(
DOMAIN,
SimpleTokenProvider.create(API_TOKEN)
)
.withHttpClient(httpClient)
.build();
assertThat(api, is(notNullValue()));
assertThat(api.getHttpClient(), is(httpClient));
}
Expand Down Expand Up @@ -98,7 +102,7 @@ public void shouldThrowWhenDomainIsNull() {
@Test
public void shouldThrowWhenApiTokenIsNull() {
verifyThrows(IllegalArgumentException.class,
() -> ManagementAPI.newBuilder(DOMAIN, null).build(),
() -> ManagementAPI.newBuilder(DOMAIN, (String) null).build(),
"'api token' cannot be null!");
}

Expand Down