# `AttestoClient.JARM`
[🔗](https://github.com/XukuLLC/attesto_client/blob/v2.26.0/lib/attesto_client/jarm.ex#L1)

Verify JWT Secured Authorization Response Mode (JARM) responses, the
client-side mirror of `Attesto.JARM.response_jwt/4`.

When a client requests a JWT response mode, the authorization server returns
the authorization response as a single signed JWT (the `response` parameter).
This verifies that JWT - signature, issuer, audience, and expiry - and returns
the response parameters (FAPI 2.0 Message Signing §5.4 / the JARM spec). It is
a verifier, not a flow runner: the host extracts `response` from the redirect
(or form post) and passes it here.

## Checks (JARM §2.4)

  * **Signature** verifies against one of the authorization server's JWKS keys,
    restricted to an algorithm allow-list (`:accepted_algs`, default the FAPI
    algorithms PS256/ES256/EdDSA/Ed25519 - `none` is never accepted). RSA keys
    require at least 2048 bits under every policy. The default FAPI policy
    restricts legacy `EdDSA` to Ed25519.
    When the JWT header carries a `kid`, exactly one suitable matching key
    must exist.
  * `iss` equals the expected authorization server identifier (`:issuer`).
  * `aud` equals, or (an all-string array) contains, the client's `client_id`
    (`:client_id`); a mixed-type `aud` array is malformed.
  * `iat`, when present, is a non-negative NumericDate not meaningfully in the
    future (a 60-second clock-skew tolerance).
  * `nbf`, when present, is a non-negative NumericDate no later than the same
    clock-skew window.
  * `exp` is present and in the future.

On success it returns `{:ok, claims}`, the full claim set - the caller reads
the response parameters (`code`/`state` on success, or `error`/
`error_description`/`state` on an error response).

# `error`

```elixir
@type error() ::
  :invalid_jwks
  | :missing_issuer
  | :missing_client_id
  | :unsupported_alg
  | :invalid_token
  | :invalid_signature
  | :ambiguous_key
  | :weak_key
  | :unsupported_critical_header
  | :invalid_policy
  | :invalid_issuer
  | :invalid_audience
  | :invalid_iat
  | :invalid_nbf
  | :not_yet_valid
  | :missing_exp
  | :expired
```

# `jwks`

```elixir
@type jwks() :: %{optional(String.t()) =&gt; term()} | [map()]
```

# `verify_opt`

```elixir
@type verify_opt() ::
  {:issuer, String.t()}
  | {:client_id, String.t()}
  | {:accepted_algs, [String.t()]}
  | {:enforce_fapi_alg_policy, boolean()}
  | {:now, integer()}
```

# `verify`

```elixir
@spec verify(String.t(), jwks(), [verify_opt()]) :: {:ok, map()} | {:error, error()}
```

Verify a JARM `response` JWT against the authorization server's `jwks`,
returning `{:ok, claims}` or `{:error, reason}`.

Required options: `:issuer` (the expected authorization server identifier) and
`:client_id` (the expected audience). Optional: `:accepted_algs` (default the
FAPI algorithms) and `:now` (Unix seconds, for tests). Supplying an explicit
`:accepted_algs` list selects a non-FAPI algorithm policy unless
`:enforce_fapi_alg_policy` is also `true`. RSA verification requires at least
2048 bits under either policy (RFC 7518 §3.3).

---

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