Supabase.Auth.Admin.OAuth (supabase_auth v1.0.1)

View Source

Admin OAuth 2.1 client management for Supabase Auth.

Provides functions to manage OAuth clients programmatically via the admin API. All operations require a client configured with a service_role key.

Only relevant when the OAuth 2.1 server is enabled in Supabase Auth.

Client Lifecycle

# Create a new OAuth client
{:ok, client} = Admin.OAuth.create_client(supabase, %{
  client_name: "My App",
  redirect_uris: ["https://myapp.com/callback"]
})

# List all clients
{:ok, clients, pagination} = Admin.OAuth.list_clients(supabase)

# Update a client
{:ok, updated} = Admin.OAuth.update_client(supabase, client.client_id, %{
  client_name: "My Renamed App"
})

# Regenerate client secret
{:ok, rotated} = Admin.OAuth.regenerate_client_secret(supabase, client.client_id)

# Delete a client
:ok = Admin.OAuth.delete_client(supabase, client.client_id)

Summary

Functions

Creates a new OAuth client.

Deletes an OAuth client.

Gets details of a specific OAuth client.

Lists all OAuth clients with optional pagination.

Regenerates the secret for an OAuth client.

Updates an existing OAuth client.

Functions

create_client(client, attrs)

Creates a new OAuth client.

Parameters

  • client - The Supabase client to use for the request.
  • attrs - The client attributes:
    • client_name - Human-readable name (required)
    • redirect_uris - List of allowed redirect URIs (required, min 1)
    • client_uri - URI of the OAuth client
    • grant_types - Allowed grant types (defaults to ["authorization_code", "refresh_token"])
    • response_types - Allowed response types (defaults to ["code"])
    • scope - Scope string
    • token_endpoint_auth_method - One of "none", "client_secret_basic", "client_secret_post"

Returns

  • {:ok, oauth_client} - The created client (includes client_secret)
  • {:error, error} - Failed to create client

Examples

iex> attrs = %{client_name: "My App", redirect_uris: ["https://myapp.com/callback"]}
iex> Supabase.Auth.Admin.OAuth.create_client(client, attrs)
{:ok, %{client_id: "...", client_name: "My App", client_secret: "...", ...}}

delete_client(client, client_id)

Deletes an OAuth client.

Parameters

  • client - The Supabase client to use for the request.
  • client_id - The ID of the OAuth client to delete.

Returns

  • :ok - Successfully deleted the client
  • {:error, error} - Failed to delete client

Examples

iex> Supabase.Auth.Admin.OAuth.delete_client(client, "client-uuid")
:ok

get_client(client, client_id)

Gets details of a specific OAuth client.

Parameters

  • client - The Supabase client to use for the request.
  • client_id - The ID of the OAuth client to retrieve.

Returns

  • {:ok, oauth_client} - The OAuth client details
  • {:error, error} - Failed to retrieve client

Examples

iex> Supabase.Auth.Admin.OAuth.get_client(client, "client-uuid")
{:ok, %{client_id: "client-uuid", client_name: "My App", ...}}

list_clients(client, params \\ %{})

Lists all OAuth clients with optional pagination.

Parameters

  • client - The Supabase client to use for the request.
  • params - Optional pagination parameters:
    • page - Page number (default: 1)
    • per_page - Number of clients per page

Returns

  • {:ok, clients, pagination} - List of OAuth clients with pagination info
  • {:error, error} - Failed to list clients

Examples

iex> Supabase.Auth.Admin.OAuth.list_clients(client)
{:ok, [%{client_id: "...", client_name: "My App", ...}], %{next_page: 2, last_page: 5, total: 42}}

regenerate_client_secret(client, client_id)

Regenerates the secret for an OAuth client.

The previous secret is immediately invalidated.

Parameters

  • client - The Supabase client to use for the request.
  • client_id - The ID of the OAuth client.

Returns

  • {:ok, oauth_client} - The client with the new client_secret
  • {:error, error} - Failed to regenerate secret

Examples

iex> Supabase.Auth.Admin.OAuth.regenerate_client_secret(client, "client-uuid")
{:ok, %{client_id: "client-uuid", client_secret: "new-secret-...", ...}}

update_client(client, client_id, attrs)

Updates an existing OAuth client.

Parameters

  • client - The Supabase client to use for the request.
  • client_id - The ID of the OAuth client to update.
  • attrs - The attributes to update (all optional):
    • client_name - Human-readable name
    • client_uri - URI of the OAuth client
    • logo_uri - URI of the client's logo
    • redirect_uris - List of allowed redirect URIs
    • grant_types - Allowed grant types
    • token_endpoint_auth_method - Token endpoint auth method

Returns

  • {:ok, oauth_client} - The updated client
  • {:error, error} - Failed to update client

Examples

iex> Supabase.Auth.Admin.OAuth.update_client(client, "client-uuid", %{client_name: "New Name"})
{:ok, %{client_id: "client-uuid", client_name: "New Name", ...}}