OriginatingRequestBinder implements RequestStateBinderInterface
Binds a `requestState` to what the specification recommends: the authenticated principal and the originating request, as its method name plus a digest of its salient parameters.
The salient parameters are an allowlist per method, so a parameter a later revision adds cannot silently change the binding: the tool or prompt name and a digest of its arguments, or the resource URI. Any other method binds by its name alone. The principal is the token's issuer, client and subject, which outlive a token refresh between two rounds; an unauthorized request binds to no principal, so its state does not verify on an authorized one, nor the other way round.
A token without a subject identifies no user: tokens of different users of
one client would share a principal. Such a request binds to a value of its
own, so the states it mints never verify. Pass a $subject resolver when
the authorization server identifies users by another claim; the issuer
and client stay part of the principal either way.
Tags
Table of Contents
Interfaces
- RequestStateBinderInterface
- Binds the `requestState` of a multi round-trip request to the request it was minted for.
Constants
- ENCODE_DEPTH : mixed = 3 * 512
Properties
- $subject : Closure|null
Methods
- __construct() : mixed
- bind() : string
- canonical() : mixed
- Sorts object members recursively, so a client re-encoding the same arguments in another member order still binds to the same digest.
- encode() : string
- principal() : array{identified: array{iss: ?string, client: ?string, sub: string}}|array{unidentified: string}
Constants
ENCODE_DEPTH
private
mixed
ENCODE_DEPTH
= 3 * 512
Properties
$subject read-only
private
Closure|null
$subject
= null
Methods
__construct()
public
__construct([callable(AccessToken): Array|null $subject = null ]) : mixed
Parameters
- $subject : callable(AccessToken): Array|null = null
-
identifies the user a token was issued for, stable across a token refresh; null when the token identifies nobody. Defaults to the
subclaim.
bind()
public
bind(Request $request, AccessToken|null $accessToken) : string
Parameters
- $request : Request
-
the request as the client sent it, before any
RequestEventlistener ran - $accessToken : AccessToken|null
-
the token the request was authorized with, null on an unauthorized transport
Return values
stringcanonical()
Sorts object members recursively, so a client re-encoding the same arguments in another member order still binds to the same digest.
private
static canonical(mixed $value[, bool $isMap = false ]) : mixed
A list stays a JSON array and any other array becomes sorted pairs
under {"map": [[key, value], ...]}, the same split schema validation
and the handler see: a map with numeric keys out of order, e.g.
{"1": "B", "0": "A"}, must not sort into the list ["A", "B"]. Not
cast to an object, as json_encode() drops object members whose name
starts with NUL. A \stdClass is a map whatever its keys, as tool
arguments keep their JSON types. Numbers bind by value: 1 and 1.0
encode alike, so a client re-encoding a number does not break its retry.
Parameters
- $value : mixed
- $isMap : bool = false
encode()
private
static encode(mixed $value) : string
Parameters
- $value : mixed
Return values
stringprincipal()
private
principal(AccessToken $accessToken) : array{identified: array{iss: ?string, client: ?string, sub: string}}|array{unidentified: string}
Parameters
- $accessToken : AccessToken