ADR-056: Authentication schemes as a value object
Status
Accepted. Builds on ADR-008: HTTP client and follows the capability pattern of ADR-041: Additional body credentials keep one transport.
Date
2026-11-17
Context
Vault takes a
Secret and an options array. Each placement reads only some
options: Header reads header and prefix, Query
reads query, Body reads body and Basic
reads username. The array cannot express that coupling.
Two mistakes therefore pass without an error:
- An option of another placement, e.g.
headerwithName Bearer, is accepted and ignored. - A misspelled key, e.g.
preffix, is ignored. For a caller that does not pass a literal array, static analysis cannot see it. The secret is then sent without its prefix, and the mistake shows only as a rejected request from the remote service.
Invalid values, such as a header name with a space, surface even later: the secret is read and audited first, and the request fails when it is built.
Decision
Add an Auth value object with one named constructor per placement:
bearer, basic,
header, api,
query and body. Each
constructor accepts only the options of its placement and validates them when
the scheme is built.
Add a feature-detectable calling capability,
Auth extending Vault, with
with. The concrete
client implements it by setting the same internal fields as
with, so both send the same request for the same
placement and options. The audit reason, timeout, pinned addresses and
additional body credentials carry over, as they do for
with.
Mark with as deprecated on the interface and on the
client. It keeps its behaviour and is removed in the next major release.
Three points deviate from the proposal in issue #171:
- A new method replaces the proposed
arrayunion on|Auth Scheme with. A union parameter would change the signature of a method that callers use today, and two meanings in one parameter keep the old shape alive.Authentication () - There is no
oauth2scheme. OAuth 2.0 authenticates with an() OAuthand has no single secret identifier;Config withalready covers it.OAuth () - The
$authconstructor parameter ofPrefix Vaultstays. Removing it changes the constructor signature, which waits for a major release.Http Client
Consequences
Vault is unchanged, so its existing implementations
keep loading. Vault still declares
Vault; a caller narrows with
instanceof Auth before it calls
with. In the next major release, http can declare the
narrower type, and with and the options array go.
Static analysis with deprecation rules reports each remaining
with call. This package's own tests keep calling it on
purpose, because they keep the deprecated method working until it is removed;
phpstan. ignores the deprecation for Tests/ only.
Unit tests send the same request through both methods for each placement and
each option. A functional test sends a header scheme with a prefix to a
local server on the blocking and the streaming path. The executed
documentation examples use with.