BankingCircle.Auth.Token (banking_circle v1.0.0)

Copy Markdown View Source

An OAuth2 JWT access token issued by Banking Circle's authorization endpoint, with the metadata needed to decide when to refresh it.

Banking Circle tokens are short-lived (documented as 5 minutes). The guidance from Banking Circle is explicit: do not fetch a fresh token on every request — only refresh once the current token has actually expired (or is about to). expiring_soon?/2 implements that with a configurable safety margin.

Summary

Functions

True if the token has already expired, or expires within margin_ms.

Builds a token from an authorization response body.

Types

t()

@type t() :: %BankingCircle.Auth.Token{
  expires_at: DateTime.t(),
  issued_at: DateTime.t(),
  value: String.t()
}

Functions

authorization_header(token)

@spec authorization_header(t()) :: {String.t(), String.t()}

expiring_soon?(token, margin_ms \\ 15000)

@spec expiring_soon?(t(), non_neg_integer()) :: boolean()

True if the token has already expired, or expires within margin_ms.

from_response(body)

@spec from_response(map()) :: t()

Builds a token from an authorization response body.

Accepts either expires_in (seconds, relative) or an explicit expires_at/expiresOn field, to be resilient to minor response variations across environments.