ProtoRune.Session behaviour (proto_rune v0.5.1)

Copy Markdown

Behaviour unifying the session types that can authenticate XRPC requests.

Two session implementations exist:

The XRPC layer dispatches through this module instead of matching on token fields, so any struct implementing the behaviour works:

{:ok, headers, session} = ProtoRune.Session.authorization_headers(session, "GET", url)

authorization_headers/3 returns the (possibly updated) session so implementations can keep per-request state, such as a DPoP nonce, explicit and testable.

Summary

Callbacks

Builds the HTTP headers authenticating a request to url.

The XRPC base URL of the service hosting the session, when known.

Functions

Dispatches to the session's authorization_headers/3 implementation.

Dispatches to the session's service_url/1 implementation.

Types

Callbacks

authorization_headers(session, method, url)

@callback authorization_headers(session :: t(), method :: String.t(), url :: String.t()) ::
  {:ok, headers :: map(), session :: t()} | {:error, term()}

Builds the HTTP headers authenticating a request to url.

method is the HTTP method of the request being authenticated ("GET", "POST", ...) and url the target URL without query string or fragment, both needed to bind DPoP proofs (RFC 9449).

service_url(session)

@callback service_url(session :: t()) :: String.t() | nil

The XRPC base URL of the service hosting the session, when known.

Functions

authorization_headers(session, method, url)

Dispatches to the session's authorization_headers/3 implementation.

service_url(session)

Dispatches to the session's service_url/1 implementation.