PhoenixKitWeb.Plugs.EnsureOAuthConfig (phoenix_kit v1.6.16)

View Source

Plug that ensures OAuth credentials are loaded into Application env before OAuth requests.

This plug loads OAuth provider credentials from the database and configures them in Application env so that Ueberauth.run_request/4 and Ueberauth.run_callback/4 can access them at runtime.

How It Works

  1. Checks if Ueberauth configuration exists in Application env
  2. If configuration is missing, loads credentials from database via OAuthConfig.configure_providers()
  3. If loading fails, returns 503 Service Unavailable error
  4. Otherwise, allows request to proceed

Usage

Used in OAuth controller before dynamic Ueberauth calls:

plug PhoenixKitWeb.Plugs.EnsureOAuthConfig
# Then in controller actions:
# Ueberauth.run_request(conn, provider, provider_config)
# Ueberauth.run_callback(conn, provider, provider_config)

Why This Is Needed

PhoenixKit stores OAuth credentials in the database. This plug ensures credentials are loaded into Application env before Ueberauth strategy modules attempt to read them.

Summary

Functions

call(conn, opts)

init(opts)