PhoenixKit.Users.OAuthAvailability (phoenix_kit v1.6.4)

View Source

Checks OAuth availability and configured providers.

This module provides runtime checks to determine if OAuth dependencies are loaded and which providers are properly configured. It enables graceful degradation when OAuth dependencies are not installed.

Summary

Functions

Gets list of configured OAuth providers.

Checks if OAuth is available (enabled in settings, Ueberauth loaded, and at least one provider configured).

Checks if OAuth is enabled in settings.

Checks if a specific provider is configured.

Checks if a specific OAuth provider is enabled in settings.

Gets OAuth status information for debugging and admin interfaces.

Checks if Ueberauth library is loaded and available.

Functions

configured_providers()

@spec configured_providers() :: [atom()]

Gets list of configured OAuth providers.

Returns a list of provider names (as atoms) that have both:

  • Credentials configured in the database
  • Provider enabled in settings

Returns an empty list if Ueberauth is not loaded or no providers are properly configured.

Examples

iex> PhoenixKit.Users.OAuthAvailability.configured_providers()
[:google, :apple]

iex> PhoenixKit.Users.OAuthAvailability.configured_providers()
[]

oauth_available?()

@spec oauth_available?() :: boolean()

Checks if OAuth is available (enabled in settings, Ueberauth loaded, and at least one provider configured).

Examples

iex> PhoenixKit.Users.OAuthAvailability.oauth_available?()
true

iex> PhoenixKit.Users.OAuthAvailability.oauth_available?()
false

oauth_enabled_in_settings?()

@spec oauth_enabled_in_settings?() :: boolean()

Checks if OAuth is enabled in settings.

Returns true if OAuth is explicitly enabled in settings, defaults to false.

Examples

iex> PhoenixKit.Users.OAuthAvailability.oauth_enabled_in_settings?()
true

provider_configured?(provider)

@spec provider_configured?(atom() | String.t()) :: boolean()

Checks if a specific provider is configured.

A provider is considered configured if:

  • It's enabled in settings
  • It has valid credentials in the database
  • Ueberauth is loaded

Examples

iex> PhoenixKit.Users.OAuthAvailability.provider_configured?(:google)
true

iex> PhoenixKit.Users.OAuthAvailability.provider_configured?(:github)
false

provider_enabled?(provider)

@spec provider_enabled?(atom()) :: boolean()

Checks if a specific OAuth provider is enabled in settings.

Returns true if both the master OAuth switch and the individual provider are enabled. Requires the master oauth_enabled setting to be true.

Examples

iex> PhoenixKit.Users.OAuthAvailability.provider_enabled?(:google)
true

iex> PhoenixKit.Users.OAuthAvailability.provider_enabled?(:apple)
false

status()

@spec status() :: map()

Gets OAuth status information for debugging and admin interfaces.

Examples

iex> PhoenixKit.Users.OAuthAvailability.status()
%{
  enabled_in_settings: true,
  ueberauth_loaded: true,
  providers: [:google, :apple],
  available: true
}

ueberauth_loaded?()

@spec ueberauth_loaded?() :: boolean()

Checks if Ueberauth library is loaded and available.

Returns true if the Ueberauth module is available, false otherwise.

Examples

iex> PhoenixKit.Users.OAuthAvailability.ueberauth_loaded?()
true

iex> PhoenixKit.Users.OAuthAvailability.ueberauth_loaded?()
false