ExMCP.Security.Consent (ex_mcp v1.0.0-rc.8)

Copy Markdown View Source

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 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.

Summary

Functions

Ensures user consent is obtained before accessing an external resource.

Functions

ensure_user_consent(user_id, url, transport, handler, config)

@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.