# `PhoenixKitWeb.Plugs.EnsureOAuthConfig`
[🔗](https://github.com/BeamLabEU/phoenix_kit/blob/v1.7.164/lib/phoenix_kit_web/plugs/ensure_oauth_config.ex#L1)

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.

# `call`

# `init`

---

*Consult [api-reference.md](api-reference.md) for complete listing*
