AttestoPhoenix.DPoP.Adapter (AttestoPhoenix v5.0.0)

Copy Markdown View Source

Resolve the callback and option boundary between AttestoPhoenix.Config and Attesto.DPoP.

The adapter deliberately stops at option construction. It never verifies a proof and never records a replay identity. Callers choose whether :replay_check is included because token-endpoint sender constraints must defer that check until the grant has validated, while PAR and device authorization verify their proof inline.

Summary

Functions

Adapt the configured mTLS certificate extractor to the verifier's 1-arity callback form.

Resolve the protected-resource DPoP htu callback, or nil when no target origin or callback is configured.

Resolve the server-issued nonce validator, or nil when unused.

Resolve the fresh-nonce issuer, or nil when nonce checks are unused.

Build the DPoP/mTLS options consumed by Attesto.Plug.Authenticate.

Adapt the configured replay callback to the verifier's 2-arity form.

Verify a DPoP proof with options built from config and input.

Types

verification_mode()

@type verification_mode() :: :inline | :deferred

Functions

cert_der(config)

@spec cert_der(AttestoPhoenix.Config.t()) :: (Plug.Conn.t() -> binary() | nil) | nil

Adapt the configured mTLS certificate extractor to the verifier's 1-arity callback form.

htu(config)

@spec htu(AttestoPhoenix.Config.t()) :: (Plug.Conn.t() -> String.t() | nil) | nil

Resolve the protected-resource DPoP htu callback, or nil when no target origin or callback is configured.

See AttestoPhoenix.RequestContext.protected_resource_url/2: a configured :htu callback or :resource_origin decides. Without either, nil is returned so protected resources that accept DPoP must pin :origin or :htu explicitly instead of trusting the request Host header.

nonce_check(config)

@spec nonce_check(AttestoPhoenix.Config.t()) ::
  (String.t() | nil -> :ok | {:error, :use_dpop_nonce}) | nil

Resolve the server-issued nonce validator, or nil when unused.

nonce_issue(config)

@spec nonce_issue(AttestoPhoenix.Config.t()) :: (-> String.t()) | nil

Resolve the fresh-nonce issuer, or nil when nonce checks are unused.

protected_resource_opts(config)

@spec protected_resource_opts(AttestoPhoenix.Config.t()) :: keyword()

Build the DPoP/mTLS options consumed by Attesto.Plug.Authenticate.

This is the protected-resource path: replay checking is disabled when DPoP is disabled, while htu, nonce, nonce issuance, and certificate extraction are resolved from the same Phoenix config used by the endpoint. When neither :htu nor :resource_origin is set on config, :htu is omitted so Attesto.Plug.Authenticate.init/1 requires an explicit per-route :origin or :htu whenever DPoP is accepted.

replay_check(config)

@spec replay_check(AttestoPhoenix.Config.t()) :: (String.t(), pos_integer() -> any())

Adapt the configured replay callback to the verifier's 2-arity form.

verification_opts(config, input, options \\ [])

@spec verification_opts(AttestoPhoenix.Config.t(), map(), keyword()) :: keyword()

Build the conn-free options for Attesto.DPoP.verify_proof/2.

:replay_check defaults to :inline, which preserves the behavior of proof binding at PAR and device authorization. Pass replay_check: :deferred for the token endpoint; that mode omits the callback and leaves the returned replay identity for the caller to commit after grant validation.

nonce_check: true adds the configured nonce callback. It is opt-in because not every DPoP proof path currently requires server-issued nonces. http_method_default preserves the device-authorization default for direct callers that do not populate the request method.

verify_proof(config, proof, input, options \\ [])

@spec verify_proof(AttestoPhoenix.Config.t(), binary(), map(), keyword()) ::
  {:ok, map()} | {:error, term()}

Verify a DPoP proof with options built from config and input.

When Canonical / :htu resolves to nil (or any non-string), returns {:error, :invalid_http_uri} instead of calling Attesto.DPoP.verify_proof/2 and raising ArgumentError.