# `ExMCP.Security.Consent`
[🔗](https://github.com/azmaveth/ex_mcp/blob/v1.0.0/lib/ex_mcp/security/consent.ex#L1)

Manages user consent for various operations.

This module is responsible for ensuring that user consent has been
obtained before proceeding with sensitive actions.

## Expiry handling

Consent handlers may express a grant's lifetime in any of the forms listed in
`t:ExMCP.ConsentHandler.expiry/0`. All of them are normalized here into the
monotonic-seconds value stored by ExMCP's internal consent cache.

Every decision path fails closed: an expiry that cannot be interpreted, is
already in the past, or is implausibly far in the future (the classic
"handler returned Unix epoch seconds where a monotonic value was expected"
bug, which would otherwise grant consent for decades) is logged and the
request is rejected with `{:error, :consent_error}` rather than cached.

# `ensure_user_consent`

```elixir
@spec ensure_user_consent(
  ExMCP.ConsentHandler.user_id(),
  String.t(),
  atom(),
  module(),
  map()
) :: :ok | {:error, :consent_denied | :consent_required | :consent_error}
```

Ensures user consent is obtained before accessing an external resource.

---

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