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

The `sub` a client is shown for a resource owner (OpenID Connect Core §8), as
conn-free core.

A client's subject type comes from the host's `:client_subject_type`
callback: `"public"` (the default, and the only type when the callback is
not configured) shows the host's own subject identifier; `"pairwise"` shows
the value `Attesto.PairwiseSubject.derive/3` computes from the client's
sector identifier, the host subject and `:pairwise_subject_salt`.

Every response that tells a client who the resource owner is goes through
this module, so one client sees one `sub` for one End-User everywhere: the
access token, ID Token, the UserInfo response, the introspection response and
the back-channel logout token. For access tokens issued to a pairwise client,
`access_token_opts/2` directs `Attesto.Token.mint/3` to emit the pairwise
`sub` alongside the AES-256-GCM sealed host subject, which `verify_opts/1`
unseals for same-deployment protected resources and introspection.

A client resolved from a Client ID Metadata Document is always `public`.

The sector identifier is the single host shared by the client's registered
redirect URIs. `sector_identifier_uri` is not supported, so a pairwise
client whose redirect URIs span hosts has no sector identifier and gets
`{:error, :multiple_hosts}` here; callers fail closed on any error and never
fall back to the host subject.

# `error`

```elixir
@type error() ::
  :pairwise_not_configured
  | :client_unavailable
  | :no_redirect_uris
  | :invalid_redirect_uri
  | :multiple_hosts
  | :unsupported_pairwise_grant
```

# `access_token_opts`

```elixir
@spec access_token_opts(AttestoPhoenix.Config.t(), term()) ::
  {:ok, keyword()} | {:error, error()}
```

Extra `Attesto.Token.mint/3` options for an access token minted for `client`.

# `for_client`

```elixir
@spec for_client(AttestoPhoenix.Config.t(), term(), String.t()) ::
  {:ok, String.t()} | {:error, error()}
```

The `sub` to show a loaded `client` for the host's `subject`.

# `for_client_id`

```elixir
@spec for_client_id(AttestoPhoenix.Config.t(), term(), String.t()) ::
  {:ok, String.t()} | {:error, error()}
```

The same, for a client known only by its `client_id`. The client is loaded
only when a pairwise client is possible; otherwise the host subject is
returned as is.

# `pairwise_possible?`

```elixir
@spec pairwise_possible?(AttestoPhoenix.Config.t()) :: boolean()
```

Whether any client of this configuration can be pairwise: the host
configured `:client_subject_type`.

# `sector_identifier`

```elixir
@spec sector_identifier(AttestoPhoenix.Config.t(), term()) ::
  {:ok, String.t()} | {:error, error()}
```

The client's sector identifier: the one host its registered redirect URIs
share (OIDC Core §8.1).

# `subject_type`

```elixir
@spec subject_type(AttestoPhoenix.Config.t(), term()) :: String.t()
```

The subject type of a loaded `client`: `"public"` or `"pairwise"`.

Raises `RuntimeError` when the host callback returns anything else.

# `subject_types_supported`

```elixir
@spec subject_types_supported(AttestoPhoenix.Config.t()) :: [String.t()]
```

The subject types this configuration issues, for discovery.

# `verify_opts`

```elixir
@spec verify_opts(AttestoPhoenix.Config.t()) :: keyword()
```

Extra `Attesto.Token.verify/3` options needed to unseal pairwise access tokens
under `config`.

---

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