Skip to content
Merged
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
66 changes: 66 additions & 0 deletions EXAMPLES.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
- [Management API usage](#management-api-usage)
- [Verifying an ID token](#verifying-an-id-token)
- [Organizations](#organizations)
- [Logging](#logging)
- [Asynchronous operations](#asynchronous-operations)

## Error handling
Expand Down Expand Up @@ -303,6 +304,71 @@ String url = auth.authorizeUrl("https://me.auth0.com/callback")
.build();
```

## Logging

The SDK is silent by default. You can enable logging to see HTTP requests and responses, which is useful for debugging.

### Enable logging with default settings

```java
import com.auth0.client.mgmt.ManagementApi;
import com.auth0.client.mgmt.core.LogConfig;

ManagementApi client = ManagementApi.builder()
.domain("{YOUR_DOMAIN}")
.token("{YOUR_API_TOKEN}")
.logging(LogConfig.builder()
.silent(false)
.build())
.build();
```

### Enable debug-level logging

```java
import com.auth0.client.mgmt.core.LogConfig;
import com.auth0.client.mgmt.core.LogLevel;

ManagementApi client = ManagementApi.builder()
.domain("{YOUR_DOMAIN}")
.token("{YOUR_API_TOKEN}")
.logging(LogConfig.builder()
.level(LogLevel.DEBUG)
.silent(false)
.build())
.build();
```

### Using a custom logger

```java
import com.auth0.client.mgmt.core.ILogger;
import com.auth0.client.mgmt.core.LogConfig;
import com.auth0.client.mgmt.core.LogLevel;

ManagementApi client = ManagementApi.builder()
.domain("{YOUR_DOMAIN}")
.token("{YOUR_API_TOKEN}")
.logging(LogConfig.builder()
.level(LogLevel.DEBUG)
.logger(new MyCustomLogger()) // implements ILogger
.silent(false)
.build())
.build();
```

Logging is also available on the async client:

```java
AsyncManagementApi asyncClient = AsyncManagementApi.builder()
.token("{YOUR_API_TOKEN}")
.tenantDomain("{YOUR_DOMAIN}")
.logging(LogConfig.builder()
.silent(false)
.build())
.build();
```

## Asynchronous operations

### Management API
Expand Down
14 changes: 9 additions & 5 deletions reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -12569,7 +12569,7 @@ client.userAttributeProfiles().list(
<dl>
<dd>

Retrieve details about a single User Attribute Profile specified by ID.
Create a User Attribute Profile
</dd>
</dl>
</dd>
Expand Down Expand Up @@ -17514,9 +17514,12 @@ client.branding().phone().templates().update(
<dd>

```java
client.branding().phone().templates().reset("id", new
HashMap<String, Object>() {{put("key", "value");
}});
client.branding().phone().templates().reset(
"id",
ResetPhoneTemplateRequestContent.of(new
HashMap<String, Object>() {{put("key", "value");
}})
);
```
</dd>
</dl>
Expand Down Expand Up @@ -31029,7 +31032,7 @@ client.users().sessions().delete("user_id");
<dl>
<dd>

List a verifiable credential templates.
List verifiable credential templates.
</dd>
</dl>
</dd>
Expand Down Expand Up @@ -31420,3 +31423,4 @@ client.verifiableCredentials().verification().templates().update(
</dd>
</dl>
</details>

Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import com.auth0.client.mgmt.core.ClientOptions;
import com.auth0.client.mgmt.core.Environment;
import com.auth0.client.mgmt.core.LogConfig;
import java.util.HashMap;
import java.util.Map;
import java.util.Optional;
Expand All @@ -23,6 +24,8 @@ public class AsyncManagementApiBuilder {

private OkHttpClient httpClient;

private Optional<LogConfig> logging = Optional.empty();

private String tenantDomain;

/**
Expand Down Expand Up @@ -67,6 +70,14 @@ public AsyncManagementApiBuilder httpClient(OkHttpClient httpClient) {
return this;
}

/**
* Configure logging for the SDK. Silent by default — no log output unless explicitly configured.
*/
public AsyncManagementApiBuilder logging(LogConfig logging) {
this.logging = Optional.of(logging);
return this;
}

/**
* Add a custom header to be sent with all requests.
* For headers that need to be computed dynamically or conditionally, use the setAdditional() method override instead.
Expand All @@ -92,6 +103,7 @@ protected ClientOptions buildClientOptions() {
setHttpClient(builder);
setTimeouts(builder);
setRetries(builder);
setLogging(builder);
for (Map.Entry<String, String> header : this.customHeaders.entrySet()) {
builder.addHeader(header.getKey(), header.getValue());
}
Expand Down Expand Up @@ -171,6 +183,18 @@ protected void setHttpClient(ClientOptions.Builder builder) {
}
}

/**
* Sets the logging configuration for the SDK.
* Override this method to customize logging behavior.
*
* @param builder The ClientOptions.Builder to configure
*/
protected void setLogging(ClientOptions.Builder builder) {
if (this.logging.isPresent()) {
builder.logging(this.logging.get());
}
}

/**
* Override this method to add any additional configuration to the client.
* This method is called at the end of the configuration chain, allowing you to add
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,11 @@ public void onResponse(@NotNull Call call, @NotNull Response response) throws IO
}
try {
switch (response.code()) {
case 400:
future.completeExceptionally(new BadRequestError(
ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class),
response));
return;
case 401:
future.completeExceptionally(new UnauthorizedError(
ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,15 +181,15 @@ public void onFailure(@NotNull Call call, @NotNull IOException e) {
}

/**
* Retrieve details about a single User Attribute Profile specified by ID.
* Create a User Attribute Profile
*/
public CompletableFuture<ManagementApiHttpResponse<CreateUserAttributeProfileResponseContent>> create(
CreateUserAttributeProfileRequestContent request) {
return create(request, null);
}

/**
* Retrieve details about a single User Attribute Profile specified by ID.
* Create a User Attribute Profile
*/
public CompletableFuture<ManagementApiHttpResponse<CreateUserAttributeProfileResponseContent>> create(
CreateUserAttributeProfileRequestContent request, RequestOptions requestOptions) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,15 +65,15 @@ public CompletableFuture<SyncPagingIterable<UserAttributeProfile>> list(
}

/**
* Retrieve details about a single User Attribute Profile specified by ID.
* Create a User Attribute Profile
*/
public CompletableFuture<CreateUserAttributeProfileResponseContent> create(
CreateUserAttributeProfileRequestContent request) {
return this.rawClient.create(request).thenApply(response -> response.body());
}

/**
* Retrieve details about a single User Attribute Profile specified by ID.
* Create a User Attribute Profile
*/
public CompletableFuture<CreateUserAttributeProfileResponseContent> create(
CreateUserAttributeProfileRequestContent request, RequestOptions requestOptions) {
Expand Down
28 changes: 24 additions & 4 deletions src/main/java/com/auth0/client/mgmt/ManagementApiBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@
*/
package com.auth0.client.mgmt;

import com.auth0.client.mgmt.core.ClientOptions;
import com.auth0.client.mgmt.core.CustomDomainInterceptor;
import com.auth0.client.mgmt.core.Environment;
import com.auth0.client.mgmt.core.OAuthTokenSupplier;
import com.auth0.client.mgmt.core.*;
import java.util.HashMap;
import java.util.Map;
import java.util.Optional;
Expand All @@ -26,6 +23,8 @@ public class ManagementApiBuilder {

private OkHttpClient httpClient;

private Optional<LogConfig> logging = Optional.empty();

private String customDomain = null;

// Domain-based initialization fields
Expand Down Expand Up @@ -168,6 +167,14 @@ public ManagementApiBuilder httpClient(OkHttpClient httpClient) {
return this;
}

/**
* Configure logging for the SDK. Silent by default — no log output unless explicitly configured.
*/
public ManagementApiBuilder logging(LogConfig logging) {
this.logging = Optional.of(logging);
return this;
}

/**
* Add a custom header to be sent with all requests.
* For headers that need to be computed dynamically or conditionally, use the setAdditional() method override instead.
Expand All @@ -188,6 +195,7 @@ protected ClientOptions buildClientOptions() {
setHttpClient(builder);
setTimeouts(builder);
setRetries(builder);
setLogging(builder);
for (Map.Entry<String, String> header : this.customHeaders.entrySet()) {
builder.addHeader(header.getKey(), header.getValue());
}
Expand Down Expand Up @@ -293,6 +301,18 @@ protected void setHttpClient(ClientOptions.Builder builder) {
}
}

/**
* Sets the logging configuration for the SDK.
* Override this method to customize logging behavior.
*
* @param builder The ClientOptions.Builder to configure
*/
protected void setLogging(ClientOptions.Builder builder) {
if (this.logging.isPresent()) {
builder.logging(this.logging.get());
}
}

/**
* Override this method to add any additional configuration to the client.
* This method is called at the end of the configuration chain, allowing you to add
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,9 @@ public ManagementApiHttpResponse<GetRefreshTokenResponseContent> get(String id,
}
try {
switch (response.code()) {
case 400:
throw new BadRequestError(
ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), response);
case 401:
throw new UnauthorizedError(
ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), response);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,15 +146,15 @@ public ManagementApiHttpResponse<SyncPagingIterable<UserAttributeProfile>> list(
}

/**
* Retrieve details about a single User Attribute Profile specified by ID.
* Create a User Attribute Profile
*/
public ManagementApiHttpResponse<CreateUserAttributeProfileResponseContent> create(
CreateUserAttributeProfileRequestContent request) {
return create(request, null);
}

/**
* Retrieve details about a single User Attribute Profile specified by ID.
* Create a User Attribute Profile
*/
public ManagementApiHttpResponse<CreateUserAttributeProfileResponseContent> create(
CreateUserAttributeProfileRequestContent request, RequestOptions requestOptions) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,14 @@ public SyncPagingIterable<UserAttributeProfile> list(
}

/**
* Retrieve details about a single User Attribute Profile specified by ID.
* Create a User Attribute Profile
*/
public CreateUserAttributeProfileResponseContent create(CreateUserAttributeProfileRequestContent request) {
return this.rawClient.create(request).body();
}

/**
* Retrieve details about a single User Attribute Profile specified by ID.
* Create a User Attribute Profile
*/
public CreateUserAttributeProfileResponseContent create(
CreateUserAttributeProfileRequestContent request, RequestOptions requestOptions) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,13 @@
package com.auth0.client.mgmt.actions.modules.types;

import com.auth0.client.mgmt.core.Nullable;
import com.auth0.client.mgmt.core.NullableNonemptyFilter;
import com.auth0.client.mgmt.core.ObjectMappers;
import com.auth0.client.mgmt.core.OptionalNullable;
import com.fasterxml.jackson.annotation.JsonAnyGetter;
import com.fasterxml.jackson.annotation.JsonAnySetter;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonSetter;
import com.fasterxml.jackson.annotation.Nulls;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
Expand Down Expand Up @@ -41,17 +40,15 @@ private GetActionModuleVersionsRequestParameters(
/**
* @return Use this field to request a specific page of the list results.
*/
@JsonInclude(value = JsonInclude.Include.CUSTOM, valueFilter = NullableNonemptyFilter.class)
@JsonProperty("page")
@JsonIgnore
public OptionalNullable<Integer> getPage() {
return page;
}

/**
* @return The maximum number of results to be returned by the server in a single response. 20 by default.
*/
@JsonInclude(value = JsonInclude.Include.CUSTOM, valueFilter = NullableNonemptyFilter.class)
@JsonProperty("per_page")
@JsonIgnore
public OptionalNullable<Integer> getPerPage() {
return perPage;
}
Expand Down
Loading
Loading