Repository navigation
feat(auth): narrow authorization_details to what a resolver still allows - #257
Merged
Merged
Conversation
An authorization server that stores a RAR grant at consent has to reconcile it with the subject's current access every time it issues or introspects a token. The list shaping for that is protocol-level (RFC 9396 entries, one array-valued field, pass-through for ungoverned types) and belongs next to grants(); the access lookup itself stays with the caller as a resolver callable.
ChiragAgg5k
requested review from
eldadfux,
lohanidamodar and
loks0n
as code owners
September 10, 2026 17:51
Contributor
|
A resolver's output replaced the field wholesale, so a live-access resolver returning everything the subject can reach today could add values the token was never granted. Intersect with the granted values so restrict() only ever narrows.
Member
Author
|
@greptile review |
loks0n
approved these changes
Sep 10, 2026
Intersecting with the granted values dropped every entry that listed a wildcard, since the resolver's concrete expansion never matches the sentinel. Callers name the wildcard, as with grants(), and only those entries take the resolver's result as the expansion; explicit grants still cannot widen.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds
restrict(string $field, callable $resolver, ?string $wildcard = null): selfandtoArray(): list<array>toUtopia\Auth\OAuth2\AuthorizationDetails.An authorization server that stores an RFC 9396 grant at consent time needs to reconcile it with the subject's current access whenever it issues or introspects a token. The list shaping for that is protocol-level and now lives next to
grants(). The access lookup itself stays with the caller as a resolver callable.Usage
The resolver receives an entry's
typeand the string values in$field, and returns the allowed subset.nullmeans the resolver does not govern that type and the entry passes through untouched. An empty result drops the entry. The result can only narrow: values the entry did not list are discarded, so a resolver cannot widen a grant. The exception is an entry that lists$wildcard(for example'*', named by the caller as withgrants()), whose resolver result is taken as the expansion. Other fields on the entry are kept, order is kept, and the receiver is never modified.At a token endpoint, the result feeds both the JWT claim and the response member:
At an introspection endpoint, the same call on the stored grant keeps the two answers consistent:
Appwrite Cloud will use this to intersect organization and project grants with live memberships at both endpoints, replacing a hand-rolled loop (appwrite-labs/cloud follow-up).
Changes
src/Auth/OAuth2/AuthorizationDetails.php:restrict()andtoArray().tests/Auth/OAuth2/AuthorizationDetailsTest.php: data-provider cases for narrowing, dropping, pass-through with order, malformed fields, non-string values, plus immutability, no-widening and wildcard-expansion checks.docs/oauth2.md: one paragraph and an example under the RAR section.Verification
Full auth suite passes locally (269 tests). Pint clean against the repo
pint.json. PHPStan level 5 clean on the touched files.