Search documentation of phoenix_kit

# PhoenixKit.Install.OAuthConfig (phoenix_kit v1.7.87)

Copy Markdown View Source

Handles OAuth configuration for PhoenixKit installation.

PhoenixKit uses fully dynamic OAuth - providers are configured at runtime from database. However, a minimal compile-time configuration is still required for Ueberauth to initialize.

## How It Works

Instead of using `plug Ueberauth` (which requires compile-time providers configuration), PhoenixKit calls Ueberauth functions directly in the OAuth controller:

    # In PhoenixKitWeb.Users.OAuth controller:
    # - request/2 calls Ueberauth.run_request/4
    # - callback/2 calls Ueberauth.run_callback/4

This approach allows:

- Minimal compile-time configuration - Only `config :ueberauth, Ueberauth, providers: %{}`
- Database-driven credentials - Credentials loaded from Settings table at runtime
- Dynamic provider management - Add/remove/modify providers without app restart

## Runtime OAuth Flow

1. User clicks "Sign in with Google"
2. `PhoenixKitWeb.Plugs.EnsureOAuthConfig` loads credentials from database
3. `PhoenixKitWeb.Users.OAuth.request/2` calls `Ueberauth.run_request/4` dynamically
4. User authenticates with provider
5. `PhoenixKitWeb.Users.OAuth.callback/2` calls `Ueberauth.run_callback/4` dynamically
6. User is logged in

## Related Modules

- `PhoenixKit.Users.OAuthConfig` - Configures credentials in Application env at runtime
- `PhoenixKit.Workers.OAuthConfigLoader` - Loads OAuth config on app startup
- `PhoenixKitWeb.Plugs.EnsureOAuthConfig` - Ensures credentials loaded before OAuth
- `PhoenixKitWeb.Users.OAuth` - OAuth controller with dynamic Ueberauth calls

## Summary

### Functions

add_oauth_configuration(igniter)

Adds OAuth configuration for PhoenixKit installation.

## Functions

# add_oauth_configuration(igniter)

Adds OAuth configuration for PhoenixKit installation.

This adds the minimal Ueberauth configuration required for compilation. OAuth providers are configured dynamically at runtime from the database.

## Parameters

- `igniter` - The igniter context

## Returns

Updated igniter with Ueberauth configuration and informational notice.

## Example

    igniter
    |> OAuthConfig.add_oauth_configuration()