# `AttestoPhoenix.AuthorizationServer.Introspection`
[🔗](https://github.com/XukuLLC/attesto_phoenix/blob/v5.0.0/lib/attesto_phoenix/authorization_server/introspection.ex#L1)

OAuth 2.0 Token Introspection (RFC 7662) and JWT-Secured Introspection
Response (RFC 9701), as conn-free core.

Evaluates token activeness through `Attesto.Introspection`, applies
`AttestoPhoenix.ProtectedResource.access_token_revoked?/2` to contained access
tokens, enforces the caller-authorization policy (RFC 7662 §2.2 and §4,
RFC 9701 §5), and optionally signs the RFC 9701 JWT response via
`Attesto.SignedIntrospection`.

## Caller authorization

An active response is released only to a caller entitled to the token.
Without `:introspection_authorize`, the caller must be the client the token
was issued to (`client_id`) or be named in the token's `aud`. Any other
authenticated client, including one that registered itself through open
dynamic registration, receives `%{"active" => false}`. A protected resource
whose resource identifier is not its `client_id` is authorized through
`:introspection_authorize`, which replaces this default.

# `response`

```elixir
@type response() :: Attesto.Introspection.response()
```

RFC 7662 §2.2 introspection response map (always carries `"active"`).

# `fetch_token`

```elixir
@spec fetch_token(map()) ::
  {:ok, String.t()} | {:error, AttestoPhoenix.OAuthError.t()}
```

Extract the required `"token"` parameter from `params`.

# `introspect`

```elixir
@spec introspect(
  AttestoPhoenix.Config.t(),
  String.t() | nil,
  String.t(),
  String.t() | nil
) ::
  response()
```

Introspect `token` for authenticated `client_id` and return the RFC 7662
response map.

# `sign_response`

```elixir
@spec sign_response(AttestoPhoenix.Config.t(), String.t(), response()) ::
  {:ok, String.t()}
```

Sign an RFC 7662 introspection `response` map as an RFC 9701 JWT audienced to
`client_id`.

---

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