# `Attesto.IdentityAssertion`
[🔗](https://github.com/XukuLLC/attesto/blob/v2.33.0/lib/attesto/identity_assertion.ex#L1)

Verify Identity Assertion JWT Authorization Grants (ID-JAGs) at the Resource
Authorization Server.

The client redeems the ID-JAG at the token endpoint with the RFC 7523 §4
JWT-bearer authorization grant. The verifier checks the signature against a
trusted JWKS supplied by the caller and returns the verified claims. The caller
selects the issuer, prevents replay, and applies authorization policy.
[ID-JAG draft -06, §§3.1 and 4.4.1](https://datatracker.ietf.org/doc/html/draft-ietf-oauth-identity-assertion-authz-grant-06#section-4.4.1).

  * The JOSE `typ` is `oauth-id-jag+jwt`, compared case-insensitively
    (RFC 7515 §4.1.9 and RFC 2045 §5.1).
  * The trusted issuer matches `iss`. The expected audience is the sole
    value in `aud`, which may be a string or a one-element array.
  * The request client matches `client_id`.
  * `iss`, `sub`, `aud`, `client_id`, `jti`, `exp`, and `iat` are required.
  * The assertion must be unexpired. The verifier allows 60 seconds of skew
    for `iat` and `nbf` and checks the configured lifetime bound.
  * The verifier checks the types of optional claims and returns validated
    `authorization_details` for the caller to process under RFC 9396.

# `claims`

```elixir
@type claims() :: %{optional(String.t()) =&gt; term()}
```

The validated, string-keyed ID-JAG claim set.

# `verify_error`

```elixir
@type verify_error() ::
  :malformed
  | :unsupported_critical_header
  | :unsupported_alg
  | :invalid_typ
  | :invalid_signature
  | :invalid_issuer
  | :invalid_audience
  | :missing_claim
  | :invalid_claims
  | :client_mismatch
  | :expired
  | :not_yet_valid
```

# `verify_opts`

```elixir
@type verify_opts() :: [
  now: DateTime.t() | non_neg_integer(),
  issuer: String.t(),
  audience: String.t(),
  client_id: String.t(),
  accepted_algs: [Attesto.SigningAlg.alg()],
  max_lifetime_seconds: pos_integer() | nil
]
```

# `max_assertion_bytes`

```elixir
@spec max_assertion_bytes() :: pos_integer()
```

Maximum accepted wire size in bytes of a compact Identity Assertion (ID-JAG).

# `peek_claims`

```elixir
@spec peek_claims(String.t()) :: {:ok, claims()} | {:error, :malformed}
```

Decode the unverified claims of a size-bounded ID-JAG for issuer selection.

Use `verify/3` with the selected trusted issuer before using any claim for
authorization.

# `peek_issuer`

```elixir
@spec peek_issuer(String.t()) :: {:ok, String.t()} | :error
```

Read the unverified `iss` claim from an assertion so the caller can select the
trusted issuer (and its JWKS) before verifying the signature.

This decodes the JWT payload WITHOUT verifying it - the returned issuer is
untrusted until `verify/3` confirms the signature and re-checks `iss` against
the caller-supplied `:issuer`. Returns `:error` for a malformed JWT or an
absent/blank `iss`.

# `sign`

```elixir
@spec sign(Attesto.Config.t(), map() | keyword(), keyword()) ::
  {:ok, String.t()} | {:error, :missing_claim | :invalid_claims}
```

Sign an Identity Assertion JWT Authorization Grant as a trust domain A
authorization server (`draft-ietf-oauth-identity-chaining-17` / RFC 10092;
`draft-ietf-oauth-identity-assertion-authz-grant-06`).

Options:

  * `:typ` - JOSE header `typ` value. Defaults to `"oauth-id-jag+jwt"` for
    ID-JAG (`urn:ietf:params:oauth:token-type:id-jag`); pass `"JWT"` for a
    plain RFC 7523 authorization grant (`urn:ietf:params:oauth:token-type:jwt`).
  * `:now` / `:lifetime` - clock override and assertion lifetime in seconds.

The issuer is always `config.issuer`. A supplied `iss` attribute must match;
a conflicting value returns `{:error, :invalid_claims}`.

# `verify`

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

Verify an ID-JAG assertion against a trusted issuer JWKS and return its claims.

`trusted_jwks` is the asserting IdP's JWK set (a `%{"keys" => [...]}` map, a
bare list of JWK maps, or a single JWK map). Required opts:

  * `:issuer` - the trusted issuer the assertion's `iss` must equal.
  * `:audience` - this server's issuer identifier the assertion's `aud` must
    identify.
  * `:client_id` - the authenticated client; the `client_id` claim must equal
    it (draft §3.1).

Optional opts:

  * `:accepted_algs` - JOSE algorithms a candidate key may sign with. Defaults
    to `Attesto.SigningAlg.allowed/0` (includes RS256, which enterprise IdPs
    commonly use - unlike the FAPI request-object default).
  * `:max_lifetime_seconds` - reject an assertion whose `exp - iat` exceeds
    this bound.
  * `:now` - the verification instant (a `DateTime` or unix seconds); defaults
    to the system clock.

Returns `{:ok, claims}` (string-keyed, including the registered claims) or
`{:error, t:verify_error/0}`. The caller maps every error to `invalid_grant`.

---

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