PhoenixKitWeb.Plugs.EnsureOAuthConfig (phoenix_kit v1.5.1)

View Source

Plug that ensures OAuth configuration is loaded before processing OAuth requests.

This plug serves as a fallback safety mechanism for cases where:

  • PhoenixKit.Supervisor starts AFTER parent application's Endpoint
  • OAuthConfigLoader worker failed to load configuration
  • Configuration was cleared or lost for any reason

How It Works

  1. Checks if Ueberauth has :providers configured
  2. If configuration is missing or invalid, loads it synchronously
  3. If loading fails, returns 503 Service Unavailable error
  4. Otherwise, allows request to proceed normally

Usage

Add this plug BEFORE Ueberauth plug in OAuth controller:

plug PhoenixKitWeb.Plugs.EnsureOAuthConfig
plug Ueberauth

Why This Is Needed

Ueberauth plug expects :providers key to exist in application config. If it's missing, Ueberauth.get_providers/2 fails with MatchError.

This plug prevents that error by ensuring configuration exists before Ueberauth plug runs.

Summary

Functions

call(conn, opts)

init(opts)