Skip to content

Commit 64caf5c

Browse files
committed
Added ManagementAPI token provider customization
1 parent 6e5d2d6 commit 64caf5c

2 files changed

Lines changed: 16 additions & 4 deletions

File tree

src/main/java/com/auth0/client/mgmt/ManagementAPI.java

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -401,7 +401,7 @@ public SelfServiceProfilesEntity selfServiceProfiles() {
401401
*/
402402
public static class Builder {
403403
private final String domain;
404-
private final String apiToken;
404+
private TokenProvider tokenProvider
405405
private Auth0HttpClient httpClient = DefaultHttpClient.newBuilder().build();
406406

407407
/**
@@ -411,7 +411,7 @@ public static class Builder {
411411
*/
412412
public Builder(String domain, String apiToken) {
413413
this.domain = domain;
414-
this.apiToken = apiToken;
414+
this.tokenProvider = SimpleTokenProvider.create(apiToken);
415415
}
416416

417417
/**
@@ -425,12 +425,22 @@ public Builder withHttpClient(Auth0HttpClient httpClient) {
425425
return this;
426426
}
427427

428+
/**
429+
* Configure the token provider with an {@link TokenProvider}.
430+
* @param tokenProvider the API Token provider to use when making requests.
431+
* @return the builder instance.
432+
*/
433+
public Builder withTokenProvider(TokenProvider tokenProvider) {
434+
this.tokenProvider = tokenProvider;
435+
return this;
436+
}
437+
428438
/**
429439
* Build a {@link ManagementAPI} instance using this builder's configuration.
430440
* @return the configured {@code ManagementAPI} instance.
431441
*/
432442
public ManagementAPI build() {
433-
return new ManagementAPI(domain, SimpleTokenProvider.create(apiToken), httpClient);
443+
return new ManagementAPI(domain, tokenProvider, httpClient);
434444
}
435445
}
436446
}

src/test/java/com/auth0/client/mgmt/ManagementAPITest.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,9 @@ public CompletableFuture<Auth0HttpResponse> sendRequestAsync(Auth0HttpRequest re
6868
};
6969

7070
ManagementAPI api = ManagementAPI.newBuilder(DOMAIN, API_TOKEN)
71-
.withHttpClient(httpClient).build();
71+
.withHttpClient(httpClient)
72+
.withTokenProvider(SimpleTokenProvider.create(API_TOKEN))
73+
.build();
7274
assertThat(api, is(notNullValue()));
7375
assertThat(api.getHttpClient(), is(httpClient));
7476
}

0 commit comments

Comments
 (0)