Shared protected-resource authentication for Phoenix endpoints.
This module owns the transport check, access-token verification wiring, and
revoked-token check used by protected-resource controllers. Endpoint actions
receive the verified claims only after this common work succeeds. Every 401
completes the synchronous :auth_denied callback before sending the response;
hosts must commit audit writes before returning (see AttestoPhoenix.EventSink).
DPoP target URI
A DPoP proof signs the URI of the request it was made for (htu, RFC 9449
§4.3), and the resource compares it with the URI it computes for the
request. That URI is chosen in this order:
- a per-route override passed to
AttestoPhoenix.Plug.Authenticate: core's:htucallback or core's:origin; - the configuration's
:htucallback; - the configuration's
:resource_originfollowed byconn.request_path(AttestoPhoenix.Config.new/1defaults:resource_originto the origin of:audiencewhen neither:htunor:resource_originis set and DPoP is enabled).
Requests never fall back to the Host header when DPoP is enabled. Pin an
explicit resource origin when it differs from :audience:
config :my_app, AttestoPhoenix.Config,
issuer: "https://auth.example.com",
audience: "https://api.example.com",
resource_origin: "https://api.example.com":resource_origin applies to every protected resource that uses this
configuration, including the bundled UserInfo and credential endpoints. When
those are served on another origin than the host's resources, set :htu
(or a per-route override) instead.
Summary
Functions
Return whether the access token identified by the claims is revoked.
Translate the Phoenix configuration into the core Attesto configuration.
Run the protected-resource verification skeleton.
Build the options consumed by Attesto.Plug.Authenticate.
Build the transport options for a protected-resource error response.
Answer a request whose verified token is refused after verification, with the
RFC 6750 §3.1 invalid_token challenge under the token's own scheme.
Return the challenge scheme for verified token claims.
Types
@type result() :: {:ok, Plug.Conn.t(), map()} | {:halt, Plug.Conn.t()}
Functions
@spec access_token_revoked?(AttestoPhoenix.Config.t(), map()) :: boolean()
Return whether the access token identified by the claims is revoked.
@spec attesto_config(AttestoPhoenix.Config.t()) :: Attesto.Config.t()
Translate the Phoenix configuration into the core Attesto configuration.
@spec authenticate(Plug.Conn.t(), AttestoPhoenix.Config.t(), String.t() | nil) :: result()
Run the protected-resource verification skeleton.
Returns {:ok, conn, claims} when endpoint-specific work may proceed, or
{:halt, conn} when the request has already been answered.
@spec authenticate_opts(AttestoPhoenix.Config.t(), String.t() | nil) :: keyword()
Build the options consumed by Attesto.Plug.Authenticate.
@spec error_opts(AttestoPhoenix.Config.t(), String.t() | nil, keyword()) :: keyword()
Build the transport options for a protected-resource error response.
@spec invalid_token( Plug.Conn.t(), AttestoPhoenix.Config.t(), String.t() | nil, map(), keyword() ) :: Plug.Conn.t()
Answer a request whose verified token is refused after verification, with the
RFC 6750 §3.1 invalid_token challenge under the token's own scheme.
Used for a revoked token, and by an endpoint whose host callback reports that the token's subject is no longer valid.
@spec scheme_of(map()) :: :dpop | :bearer
Return the challenge scheme for verified token claims.