# `BankingCircle.Auth.Token`
[🔗](https://github.com/iamkanishka/banking_circle/blob/main/lib/banking_circle/auth/token.ex#L1)

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.

# `t`

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

# `authorization_header`

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

# `expiring_soon?`

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

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

# `from_response`

```elixir
@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.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
