AttestoClient.DPoP (AttestoClient v2.3.0)

Copy Markdown View Source

Build DPoP proof JWTs (RFC 9449 §4), the client-side mirror of Attesto.DPoP.verify/3.

A proof is a JWT, typed dpop+jwt, whose header carries the client's public key (as jwk) and whose payload binds the proof to a single HTTP request:

  • htm - the request method ("POST", "GET", ...), uppercased.
  • htu - the request URI with any query and fragment stripped (§4.2).
  • iat - issuance time.
  • jti - a unique identifier the server tracks against replay.
  • ath - base64url(SHA-256(access_token)), present only when the proof accompanies an access token (the resource-request leg, §4.2); it binds the proof to that token so a leaked proof cannot be paired with another.
  • nonce - a server-supplied DPoP nonce, echoed when the server has demanded one (a use_dpop_nonce error carrying a DPoP-Nonce header).

Signing and key-bound :alg/:kid validation behave as in AttestoClient.Wallet.Proof (shared AttestoClient.Builder internals): the proof's public jwk is this key, and the server pins the token to its jkt thumbprint.

Summary

Functions

Build a signed DPoP proof for a request to htu with method htm, returning {:ok, compact_jws} or {:error, reason}. Fails fast on invalid input.

Types

build_opt()

@type build_opt() ::
  {:access_token, String.t()}
  | {:nonce, String.t()}
  | {:alg, String.t()}
  | {:kid, String.t()}
  | {:now, integer()}
  | {:jti, String.t()}

error()

@type error() ::
  :invalid_key
  | :invalid_htm
  | :invalid_htu
  | :invalid_time
  | :unsupported_alg
  | :unsupported_key
  | {:signing_failed, String.t()}

jwk()

@type jwk() :: JOSE.JWK.t() | map()

Functions

proof(jwk, htm, htu, opts \\ [])

@spec proof(jwk(), String.t(), String.t(), [build_opt()]) ::
  {:ok, String.t()} | {:error, error()}

Build a signed DPoP proof for a request to htu with method htm, returning {:ok, compact_jws} or {:error, reason}. Fails fast on invalid input.

jwk is the DPoP key (private half required for signing). htm is the HTTP method and htu the target URI; the URI's query and fragment are stripped to form the htu claim. Pass :access_token on a resource request so the proof carries the ath binding, and :nonce to echo a server-demanded DPoP nonce. :alg, :kid, and :now behave as in AttestoClient.Wallet.Proof.build/2.