📚 Documentation · 🚀 Getting Started · 💬 Feedback
Warning
This SDK is currently in beta. APIs may change in backwards-incompatible ways before the stable release.
- API Reference - Complete API reference documentation.
- Docs site — explore our docs site and learn more about Auth0.
- Java 8+
implementation 'com.auth0:myaccount-java:1.0.0-beta.0'<dependency>
<groupId>com.auth0</groupId>
<artifactId>myaccount-java</artifactId>
<version>1.0.0-beta.0</version>
</dependency>The MyAccountClient wraps the API with automatic authentication, Auth0 telemetry headers, and domain-based URL derivation. Instantiate it with your Auth0 tenant domain and the signed-in end user's access token:
import com.auth0.client.myaccount.auth.MyAccountClient;
MyAccountClient client = MyAccountClient
.builder()
.domain("tenant.auth0.com")
.staticToken("<user-access-token>")
.build();
client.authenticationMethods().list();
client.factors().list();Note: Supply a bare
domain(e.g.,tenant.auth0.com) — not a full URL. The client derives the base URLhttps://{domain}/me/v1for you. Values that include a scheme (https://) or a trailing slash are rejected.
The My Account API is a user-scoped API (/me/v1) and authenticates with the signed-in
end user's access token (audience https://{domain}/me/, with me: scopes). Application-only
grants (client credentials, private key JWT) are intentionally not supported.
The client obtains a bearer token before every request. Configure it with either a static token or a dynamic token provider.
Use a fixed end-user access token:
import com.auth0.client.myaccount.auth.MyAccountClient;
MyAccountClient client = MyAccountClient
.builder()
.domain("tenant.auth0.com")
.staticToken("<user-access-token>")
.build();For tokens that change over time (for example, per-request tokens sourced from the current
user session), supply a TokenProvider. It is invoked before each request, so the token can
refresh dynamically. TokenProvider is a functional interface, so a lambda works for simple
cases:
import com.auth0.client.myaccount.auth.MyAccountClient;
import com.auth0.client.myaccount.auth.Token;
MyAccountClient client = MyAccountClient
.builder()
.domain("tenant.auth0.com")
.tokenProvider(() -> Token.of(session.getAccessToken()))
.build();For non-blocking calls, use AsyncMyAccountClient. It exposes the same builder options as
MyAccountClient and returns CompletableFuture results:
import com.auth0.client.myaccount.auth.AsyncMyAccountClient;
import com.auth0.client.myaccount.auth.Token;
AsyncMyAccountClient client = AsyncMyAccountClient
.builder()
.domain("tenant.auth0.com")
.tokenProvider(() -> Token.of(session.getAccessToken()))
.build();
client.factors().list();For PATCH requests, the SDK uses OptionalNullable<T> to handle three-state nullable semantics:
- ABSENT: Field not provided (omitted from JSON)
- NULL: Field explicitly set to null (included as
nullin JSON) - PRESENT: Field has a non-null value
import com.auth0.client.myaccount.core.OptionalNullable;
UpdateRequest request = UpdateRequest.builder()
.fieldName(OptionalNullable.absent()) // Skip field
.anotherField(OptionalNullable.ofNull()) // Clear field
.yetAnotherField(OptionalNullable.of("value")) // Set value
.build();- Required fields: For required fields, you cannot use
absent(). Required fields must always be present with either a non-null value or explicitly set to null usingofNull(). - Type safety:
OptionalNullable<T>is not fully type-safe since all three states use the same type, but it provides a cleaner API than nestedOptional<Optional<T>>for handling three-state nullable semantics.
When the API returns a non-success status code (4xx or 5xx response), an API exception will be thrown.
import com.auth0.client.myaccount.core.MyAccountApiException;
try{
client.authenticationMethods().create(...);
} catch (MyAccountApiException e){
// Do something with the API exception...
}This SDK is built to work with any instance of OkHttpClient. By default, if no client is provided, the SDK will construct one.
However, you can pass your own client like so:
import com.auth0.client.myaccount.auth.MyAccountClient;
import okhttp3.OkHttpClient;
OkHttpClient customClient = ...;
MyAccountClient client = MyAccountClient
.builder()
.domain("tenant.auth0.com")
.staticToken("<user-access-token>")
.httpClient(customClient)
.build();The SDK is instrumented with automatic retries with exponential backoff. A request will be retried as long
as the request is deemed retryable and the number of retry attempts has not grown larger than the configured
retry limit (default: 2). Before defaulting to exponential backoff, the SDK will first attempt to respect
the Retry-After header (as either in seconds or as an HTTP date), and then the X-RateLimit-Reset header
(as a Unix timestamp in epoch seconds); failing both of those, it will fall back to exponential backoff.
Which status codes are retried depends on the retry-status-codes generator configuration:
legacy (current default): retries on
recommended: retries on
- 408 (Timeout)
- 429 (Too Many Requests)
- 502 (Bad Gateway)
- 503 (Service Unavailable)
- 504 (Gateway Timeout)
Use the maxRetries client option to configure this behavior.
import com.auth0.client.myaccount.auth.MyAccountClient;
MyAccountClient client = MyAccountClient
.builder()
.domain("tenant.auth0.com")
.staticToken("<user-access-token>")
.maxRetries(1)
.build();The SDK defaults to a 60 second timeout. You can configure this with a timeout option at the client or request level.
import com.auth0.client.myaccount.auth.MyAccountClient;
import com.auth0.client.myaccount.core.RequestOptions;
// Client level
MyAccountClient client = MyAccountClient
.builder()
.domain("tenant.auth0.com")
.staticToken("<user-access-token>")
.timeout(60)
.build();
// Request level
client.authenticationMethods().create(
...,
RequestOptions
.builder()
.timeout(60)
.build()
);The SDK allows you to add custom headers to requests. You can configure headers at the client level or at the request level.
import com.auth0.client.myaccount.auth.MyAccountClient;
import com.auth0.client.myaccount.core.RequestOptions;
// Client level
MyAccountClient client = MyAccountClient
.builder()
.domain("tenant.auth0.com")
.staticToken("<user-access-token>")
.addHeader("X-Custom-Header", "custom-value")
.addHeader("X-Request-Id", "abc-123")
.build();
;
// Request level
client.authenticationMethods().create(
...,
RequestOptions
.builder()
.addHeader("X-Request-Header", "request-value")
.build()
);The SDK provides access to raw response data, including headers, through the withRawResponse() method.
The withRawResponse() method returns a raw client that wraps all responses with body() and headers() methods.
(A normal client's response is identical to a raw client's response.body().)
MyAccountApiHttpResponse response = client.authenticationMethods().withRawResponse().create(...);
System.out.println(response.body());
System.out.println(response.headers().get("X-My-Header"));While we value open-source contributions to this SDK, this library is generated programmatically. Additions made directly to this library would have to be moved over to our generation code, otherwise they would be overwritten upon the next generated release. Feel free to open a PR as a proof of concept, but know that we will not be able to merge it as-is. We suggest opening an issue first to discuss with us!
On the other hand, contributions to the README are always very welcome!
To provide feedback or report a bug, please raise an issue on our issue tracker.
Please do not report security vulnerabilities on the public GitHub issue tracker. The Responsible Disclosure Program details the procedure for disclosing security issues.

Auth0 is an easy to implement, adaptable authentication and authorization platform.
To learn more check out Why Auth0?
This project is licensed under the Apache-2.0 license. See the LICENSE file for more info.
