Skip to content

feat(grants): support subject grant requests and responses - #11

Merged
adrianboros merged 2 commits into
mainfrom
feat/subject-grants
Oct 7, 2026
Merged

adrianboros merged 2 commits into
mainfrom
feat/subject-grants

Conversation

@adrianboros

@adrianboros adrianboros commented Oct 7, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Open Payments spec v1.3 adds grants for subject information. A client uses them to check that a user owns a wallet address ("verify wallet address ownership" guide on openpayments.dev).

The SDK could not run this flow:

  • The grant request schema required access_token, so a request with only subject failed validation.
  • continue() always expected access_token in the response. A response with only subject and continue failed.

This PR adds support for it. The docs need it for the PHP snippets.

Changes

  • Request schema: a request needs client, and access_token or (interact and subject). This follows the spec. Added schemas for subject and interact. interact.finish can be null, because GrantInteraction::toArray() sends null when there is no finish.
  • New models: Subject and SubjectId.
  • Grant: access_token is now nullable. Added subject. The constructor stays compatible (subject is an optional third parameter).
  • GrantContinue::$access_token is now AccessToken|SimpleAccessToken. A subject-only grant has no access rights, so its continue token is a SimpleAccessToken. ->value works for both.
  • GrantTransformer:
    • reads subject
    • builds a grant without an access token
    • throws UnexpectedValueException when the response has no valid continue
    • throws UnexpectedValueException when the grant is still pending (no access_token and no subject). Before, these cases threw an InvalidArgumentException or a TypeError.
  • Tests: validator, transformer and service tests for subject grants and the new errors.
  • CI: Pint also checks tests/Transformers.
  • CHANGELOG updated.

Notes for callers

Grant::$access_token and GrantContinue::$access_token changed type. Runtime behavior for access token grants is the same. Code checked with static analysis may need a null check or an instanceof check. I think this is fine for a minor release (v1.2.0), because the spec added this response shape.

Client (second commit)

  • The request schema accepts all spec v1.3 client forms: wallet address string, {walletAddress} and {jwk}.
  • request() keeps a caller client only when it is ['jwk' => ...] (directed identity), like the Node SDK clientOverride. Any other value is replaced with the configured wallet address, as before. continue() always sends the configured wallet address, as before.
  • The schema rejects a jwk client on an interactive request (the spec allows it only for non-interactive grants), a jwk with a private key (d), and an x value that is not 43 base64url characters.
  • PendingGrantTransformer called SimpleAccessToken with 3 arguments. It now passes 1. This only fixes a PHPStan error; runtime behavior is the same.

Testing

  • vendor/bin/phpunit tests: 138 tests pass on PHP 8.3.
  • Tested against the test wallet: a grant request with subject returns a pending grant with an interaction URL.
  • Pint and PHPStan (CI settings) pass.

@adrianboros adrianboros self-assigned this Oct 7, 2026
@adrianboros
adrianboros merged commit bd73667 into main Oct 7, 2026
1 check passed
@adrianboros
adrianboros deleted the feat/subject-grants branch October 7, 2026 09:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant