Auth0Api

Elixir client for the Auth0 Management API v2 and the Authentication API (access tokens with the client credentials flow).

Requirements

These come from the HTTP client dependencies (httpoison 3.0 and hackney 4). The Elixir version is declared in mix.exs; the OTP version is not checked by Mix, so make sure you run on OTP 27 or later.

Installation

The package can be installed by adding auth0_api to your list of dependencies in mix.exs:

def deps do
[
{:auth0_api, "~> 2.5"}
]
end

auth0_api depends on {:httpoison, "~> 3.0"} and {:hackney, "~> 4.1"}. If your application depends on httpoison 2.x or hackney 1.x directly, upgrade them too.

The library starts its own supervision tree (Auth0.Application, which runs the token cache) when the :auth0_api application starts. This happens automatically for a normal dependency. If the application is not started (for example with runtime: false), requests still work, but tokens are not cached.

Basic Usage

  1. Set Domain, Client ID and Client Secret:
config = %Auth0.Config{
domain: "xxx.auth0.com",
client_id: "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
client_secret: "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
}
# or API Token instead
config = %Auth0.Config{
domain: "xxx.auth0.com",
api_token: "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
}

or You can use environment variable with keys below:

Other options of %Auth0.Config{}:

Option Default Description
:http_protocol "https" "https" or "http". "http" is for tests and local mock servers only (see HTTP protocol). Any other value raises ArgumentError.
:recv_timeout 5000 Milliseconds to wait for a response after the request is sent. A request that times out returns {:error, :timeout} (raw_request/5 returns {:error, %HTTPoison.Error{reason: :timeout}}).
:connect_timeout 8000 Milliseconds to wait for a connection (DNS lookup and TCP connect).
:max_request_retry_count 3 Max retry count when the rate limit is exceeded.
:token_cache_disabled false Disable the token cache.
:clear_token_cache false Clear the cached token and fetch a new one.

:recv_timeout and :connect_timeout must be positive integers (nil means the default; :infinity is not accepted). They apply to both Management API and Authentication API requests, including the token requests made by the token cache.

  1. Call Management API.

Normal Usage

params = %{
include_totals: true
}
Auth0.Api.Management.get_users(params, config)

Raw Usage

body = %{}
headers = %{}
Auth0.Common.Management.Http.raw_request(:get, "/api/v2/users?include_totals=true", body, headers, config)

Query parameters with multiple values

For query parameters that the API defines as arrays, pass a list. The key is sent once per value (strategy=auth0&strategy=google-oauth2):

Auth0.Api.Management.get_connections(%{strategy: ["auth0", "google-oauth2"]}, config)

nil values in the list are skipped. Scalar values are sent as before.

Path parameters

The functions for the endpoints newly supported in 2.5.0 percent-encode path parameters, so pass IDs as they are (for example "auth0|123", sent as auth0%7C123). Their @doc says "Path parameters are percent-encoded".

All other functions insert path parameters as given, without encoding, so that existing callers who already encode IDs keep working. This includes the functions that existed before 2.5.0 and the 5 functions added in 2.5.0 for endpoints the library already supported internally (get_prompt_rendering, update_prompt_rendering, update_session, and the Bot Detection functions). For those functions, encode an ID yourself if it can contain characters such as |, /, ? or #. Encoding them all consistently is planned for the next major version.

Custom domain header

Functions whose endpoints accept the auth0-custom-domain header take an optional opts keyword list as their last argument. Auth0 then uses that custom domain for the links it generates (for example in verification emails and tickets):

Auth0.Api.Management.create_password_change_ticket(params, config, custom_domain: "login.example.com")

Supported by create_user, update_user, create_email_verification_ticket, create_password_change_ticket, send_job_verification_email, create_organization_invitation, create_guardian_enrollment_ticket, create_self_service_profile_sso_ticket and test_branding_phone_template. Only a host name, optionally with a port, is accepted; any other value (including one containing CR/LF) raises ArgumentError. Without the option, no header is sent.

Authentication API

To get an access token for an API (audience) with the client credentials flow, use the Authentication API:

params = %Auth0.Authentication.Token.ClientCredentials.Params{
audience: "https://xxx.auth0.com/api/v2/",
client_id: "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
client_secret: "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
}
{:ok, %Auth0.Entity.Token{access_token: access_token}} =
Auth0.Authentication.token_by_client_credentials(params, config)

config is used only for the request settings (domain, http_protocol, the timeouts and the retry count); the client credentials sent to Auth0 are the ones in params, not config.client_id / config.client_secret.

The Management API functions get and cache their tokens by themselves, so you do not need to call this for them.

HTTP protocol

Warning: http_protocol: "http" sends every credential in plain text: the API token, the client secret (to /oauth/token) and access tokens. Use it only for tests and local mock servers. Never use it with a real Auth0 tenant.

# For tests against a local mock server only
config = %Auth0.Config{domain: "localhost:4000", http_protocol: "http", api_token: "test-token"}

Connection pools

Requests use a dedicated hackney connection pool for each Auth0 domain (named {:auth0_api, domain}), not hackney's shared :default pool. A slow or unreachable tenant therefore does not block requests to other tenants, or your application's own requests that use hackney's :default pool.

A pool is started on the first request to a domain and stays until hackney stops, so one pool exists for each domain the library has been used with. Use a fixed set of trusted domains; do not build :domain from untrusted input. Settings of hackney's :default pool do not apply to this library's requests.

Sensitive values

inspect/2 output of Auth0.Config (:api_token, :client_secret), Auth0.Authentication.Token.ClientCredentials.Params (:client_secret) and Auth0.Entity.Token (:access_token, :refresh_token, :id_token) does not include these values, so they do not appear in logs or crash reports that inspect the structs. This does not apply to inspect(value, structs: false) or to maps built with Map.from_struct/1.

Rate Limiting

The library handles Auth0's rate limiting automatically. When a 429 Too Many Requests response is received, it checks the Retry-After header and waits for the specified duration before retrying. If the header is missing, it falls back to an exponential backoff strategy.

Supported endpoints

The library follows the official Auth0 Management API v2 OpenAPI specification as of 2026-09-24. Beta endpoints are intentionally not supported. Functions for Early Access endpoints say so in their @doc.

All Management API functions are documented in Auth0.Api.Management.

Deprecations

The following functions of Auth0.Api.Management are marked with @deprecated. They still work and will not be removed before the next major version, but calling them produces a compile-time warning. If you compile with --warnings-as-errors, migrate these calls first, or the build fails.

Functions Reason Migrate to
get_hooks, create_hook, get_hook, update_hook, delete_hook Auth0 has announced the end of life of Hooks Auth0 Actions: get_actions, create_action (then deploy_action and update_action_trigger_bindings), get_action, update_action, delete_action
get_hook_secrets, add_hook_secrets, update_hook_secrets, delete_hook_secrets Auth0 has announced the end of life of Hooks The secrets of an action (get_action, update_action)
get_rules, create_rule, get_rule, update_rule, delete_rule Auth0 has announced the end of life of Rules Auth0 Actions: get_actions, create_action (then deploy_action and update_action_trigger_bindings), get_action, update_action, delete_action
get_blacklisted_tokens, blacklist_token Removed from the Management API No direct replacement; use purpose-specific revocation such as revoke_refresh_tokens or revoke_session
create_risk_assessment, get_risk_assessment Not part of the Management API get_risk_assessments_settings, update_risk_assessments_settings, get_risk_assessments_new_device_settings, update_risk_assessments_new_device_settings, clear_user_risk_assessments
create_supplemental_signal, get_supplemental_signal Not part of the Management API get_supplemental_signals, update_supplemental_signals

Some parameters are deprecated by Auth0 while the functions are not; they are noted in the @doc of the functions that use them: enabled_clients of connections (use get_connection_clients / update_connection_clients), deprecated connection options and strategies, oidc_backchannel_logout of clients (use oidc_logout) and include_totals of get_log_events.

Release Notes

2.5.1

See CHANGELOG.md for details. The library code is unchanged from 2.5.0.

2.5.0

See CHANGELOG.md for details.

2.4.0

See CHANGELOG.md for details, including breaking changes.

2.3.0

2.2.0

2.1.0

The docs can be found at https://hexdocs.pm/auth0_api.

License

Released under the MIT License. See LICENSE.