# `AttestoPhoenix.Plug.CORS`
[🔗](https://github.com/XukuLLC/attesto_phoenix/blob/v5.0.0/lib/attesto_phoenix/plug/cors.ex#L1)

Cross-Origin Resource Sharing (CORS) support for authorization-server and
protected-resource endpoints (RFC 10017 §6.3.3.4).

Browser-based OAuth clients make cross-origin `fetch()` calls to metadata,
JWKS, token, revocation, introspection, dynamic registration, UserInfo, and
protected-resource endpoints, including `OPTIONS` preflight requests when
sending `Authorization`, `DPoP`, or `Content-Type: application/json` headers.

Policy resolution order:

  1. The `:origins` option passed to the plug or helper.
  2. `:cors_origins` on `conn.private[:attesto_phoenix_config]`.
  3. Default `:*` (wildcard `Access-Control-Allow-Origin: *`, never paired
     with `Access-Control-Allow-Credentials`).

Set `cors_origins: false` to disable CORS headers and refuse preflights
through the router's normal missing-route handling, or configure an
explicit list of allowed origins (`["https://app.example"]`) or a 1-arity
predicate callback (`(origin -> boolean())`). When an allowlist or callback
is used, responses vary by `Origin` (`Vary: origin`) and only echo a
matching origin.

# `apply_headers`

```elixir
@spec apply_headers(Plug.Conn.t(), keyword()) :: Plug.Conn.t()
```

Applies CORS response headers to `conn` according to the active policy.

Existing `access-control-allow-origin` headers set earlier in the pipeline
are preserved.

# `preflight`

```elixir
@spec preflight(Plug.Conn.t(), keyword()) :: Plug.Conn.t()
```

Answers an HTTP `OPTIONS` CORS preflight request with `204 No Content` and
halted connection state. When the effective policy is `false`, raises
`Phoenix.Router.NoRouteError` with the connection and router. Outside a
Phoenix router, sends an empty `404` response instead.

---

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