Req plugin for OAuth 2.0 DPoP client proof generation.
Attach the plugin to a Req.Request with attach/2:
key = ReqDPoP.Key.generate(:es256)
client =
Req.new(base_url: "https://api.example.com")
|> ReqDPoP.attach(key: key, access_token: access_token)
Req.get!(client, url: "/resource")To use proof-only mode for token endpoint requests, omit :access_token.
Summary
Functions
Attaches DPoP proof generation to a Req.Request.
Builds a compact DPoP proof JWT.
Builds a compact DPoP proof JWT or raises ReqDPoP.Error.
Types
@type alg() :: :es256 | :rs256
@type attach_option() :: proof_option() | {:retry_on_nonce, boolean()} | {:max_nonce_retries, non_neg_integer()}
@type clock() :: (-> integer()) | (Req.Request.t() -> integer())
@type jti() :: (-> binary()) | (Req.Request.t() -> binary())
@type proof_option() :: {:key, ReqDPoP.Key.t() | JOSE.JWK.t() | map()} | {:access_token, binary() | (-> binary() | nil) | (Req.Request.t() -> binary() | nil)} | {:nonce, binary() | (-> binary() | nil) | (Req.Request.t() -> binary() | nil)} | {:clock, clock()} | {:jti, jti()} | {:alg, alg()}
Functions
@spec attach(Req.Request.t(), [attach_option()]) :: Req.Request.t()
Attaches DPoP proof generation to a Req.Request.
Options:
:key- required DPoP private key. AcceptsReqDPoP.Key,JOSE.JWK, or a JWK map.:access_token- optional token string or function. When present, the plugin addsAuthorization: DPoP ...and computes the proofathclaim.:nonce- optional static nonce or function.:retry_on_nonce- retries once on DPoP nonce challenges by default.:max_nonce_retries- defaults to1.:clock- injectable Unix-second clock for tests.:jti- injectable JTI generator for tests.:alg-:es256by default.:rs256is also supported.
@spec proof([proof_option() | {:htm, binary() | atom()} | {:htu, binary()}]) :: {:ok, binary()} | {:error, ReqDPoP.Error.t()}
Builds a compact DPoP proof JWT.
Required options are :key, :htm, and :htu. :access_token adds ath;
:nonce adds nonce.
@spec proof!([proof_option() | {:htm, binary() | atom()} | {:htu, binary()}]) :: binary()
Builds a compact DPoP proof JWT or raises ReqDPoP.Error.