Search documentation of phoenix_kit

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

Copy Markdown View Source

Runtime OAuth configuration management using database credentials.

This module provides functions to configure OAuth providers at runtime by reading credentials from the database and updating the application configuration dynamically.

## Summary

### Functions

configure_provider(provider)

Configures a specific OAuth provider from database settings.

configure_providers()

Configures all OAuth providers from database settings.

test_connection(provider)

Tests OAuth connection for a specific provider.

validate_credentials(provider)

Validates OAuth credentials for a specific provider.

## Functions

# configure_provider(provider)

Configures a specific OAuth provider from database settings.

## Examples

    iex> PhoenixKit.Users.OAuthConfig.configure_provider(:google)
    :ok

# configure_providers()

Configures all OAuth providers from database settings.

This function reads OAuth credentials from the database and updates the application configuration at runtime. It should be called:

- On application startup
- After updating OAuth credentials via admin UI

Skips configuration if OAuth is disabled in settings (oauth_enabled = false).

## Examples

    iex> PhoenixKit.Users.OAuthConfig.configure_providers()
    :ok

# test_connection(provider)

Tests OAuth connection for a specific provider.

This function validates the credentials format but does not make actual API calls. For true connection testing, OAuth flow needs to be initiated through the browser.

## Examples

    iex> PhoenixKit.Users.OAuthConfig.test_connection(:google)
    {:ok, "Google OAuth credentials are properly formatted"}

# validate_credentials(provider)

Validates OAuth credentials for a specific provider.

Returns `{:ok, provider}` if credentials are valid, or `{:error, reason}` if not. Uses direct database read for accurate validation.

## Examples

    iex> PhoenixKit.Users.OAuthConfig.validate_credentials(:google)
    {:ok, :google}

    iex> PhoenixKit.Users.OAuthConfig.validate_credentials(:apple)
    {:error, "Missing Apple private key"}