Supabase.Auth.OAuth (supabase_auth v1.0.1)

View Source

OAuth 2.1 authorization server APIs for grant management and consent flows.

Provides functions to manage third-party app access and handle authorization consent requests. All operations require an authenticated session.

Grant Management

List and revoke OAuth grants for authorized applications:

# List all grants
{:ok, grants} = OAuth.list_grants(client, session)

# Revoke access for a specific client
:ok = OAuth.revoke_grant(client, session, client_id)

Authorization Flow

Handle OAuth consent requests in three steps:

# 1. Get authorization details
{:ok, details} = OAuth.get_authorization_details(client, session, auth_id)

# 2a. Approve the request
{:ok, response} = OAuth.approve_authorization(client, session, auth_id)
# or 2b. Deny the request
{:ok, response} = OAuth.deny_authorization(client, session, auth_id)

# 3. Redirect user to response.redirect_url

If the user previously consented, get_authorization_details/3 returns a redirect_url immediately. Check for this to skip the consent screen:

case OAuth.get_authorization_details(client, session, auth_id) do
  {:ok, %{redirect_url: url}} when not is_nil(url) ->
    # Already consented, redirect immediately
  {:ok, details} ->
    # Show consent screen
end

For integration examples, see the OAuth guide in the documentation.