Kinde.ManagementAPI (kinde v2.1.0)

Copy Markdown View Source

Client for the Kinde Management API.

Starts as a GenServer under the application supervisor and automatically obtains and renews an access token using the client credentials flow.

Configuration

config :kinde, :management_api,
  client_id: "management_client_id",
  client_secret: "management_client_secret",
  business_domain: "https://yourapp.kinde.com"  # defaults to :domain

If :business_domain is not set, the top-level :domain config value is used.

The server returns :ignore on startup when required keys are missing, so the application can still boot without Management API credentials.

Summary

Functions

Returns a specification to start this module under a supervisor.

Deletes all MFA settings for a user.

Fetches a user by their Kinde ID.

Fetches all users, handling pagination automatically.

Functions

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

delete_mfa(kinde_id, server \\ __MODULE__)

@spec delete_mfa(String.t(), GenServer.server()) :: :ok | {:error, term()}

Deletes all MFA settings for a user.

Returns :ok on success, {:error, %APIError{}} on API errors, or {:error, %NoAccessTokenError{}} if the access token hasn't been obtained yet.

Examples

iex> Kinde.ManagementAPI.delete_mfa("kp_abc123def456")
:ok

get_user(kinde_id, server \\ __MODULE__)

@spec get_user(String.t(), GenServer.server()) :: {:ok, map()} | {:error, term()}

Fetches a user by their Kinde ID.

Returns {:ok, user_map} on success, {:error, %APIError{}} on API errors, or {:error, %NoAccessTokenError{}} if the access token hasn't been obtained yet.

Examples

iex> Kinde.ManagementAPI.get_user("kp_abc123def456")
{:ok, %{"first_name" => "Mary", "last_name" => "Doe", ...}}

list_users(server \\ __MODULE__)

@spec list_users(GenServer.server()) :: {:ok, [map()]} | {:error, term()}

Fetches all users, handling pagination automatically.

Returns {:ok, [user_map]} with a flat list of all users across all pages.

Examples

iex> Kinde.ManagementAPI.list_users()
{:ok, [%{"first_name" => "John", ...}, %{"first_name" => "Jane", ...}]}