PhoenixKitWeb.Plugs.EnsureOAuthConfig (phoenix_kit v1.6.16)
View SourcePlug 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
- Checks if Ueberauth configuration exists in Application env
- If configuration is missing, loads credentials from database via
OAuthConfig.configure_providers() - If loading fails, returns 503 Service Unavailable error
- 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.