Repository navigation
feat(grants): support subject grant requests and responses - #11
Merged
Merged
Conversation
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
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:
access_token, so a request with onlysubjectfailed validation.continue()always expectedaccess_tokenin the response. A response with onlysubjectandcontinuefailed.This PR adds support for it. The docs need it for the PHP snippets.
Changes
client, andaccess_tokenor (interactandsubject). This follows the spec. Added schemas forsubjectandinteract.interact.finishcan benull, becauseGrantInteraction::toArray()sendsnullwhen there is no finish.SubjectandSubjectId.Grant:access_tokenis now nullable. Addedsubject. The constructor stays compatible (subjectis an optional third parameter).GrantContinue::$access_tokenis nowAccessToken|SimpleAccessToken. A subject-only grant has no access rights, so its continue token is aSimpleAccessToken.->valueworks for both.GrantTransformer:subjectUnexpectedValueExceptionwhen the response has no validcontinueUnexpectedValueExceptionwhen the grant is still pending (noaccess_tokenand nosubject). Before, these cases threw anInvalidArgumentExceptionor aTypeError.tests/Transformers.Notes for callers
Grant::$access_tokenandGrantContinue::$access_tokenchanged type. Runtime behavior for access token grants is the same. Code checked with static analysis may need a null check or aninstanceofcheck. I think this is fine for a minor release (v1.2.0), because the spec added this response shape.Client (second commit)
clientforms: wallet address string,{walletAddress}and{jwk}.request()keeps a callerclientonly when it is['jwk' => ...](directed identity), like the Node SDKclientOverride. Any other value is replaced with the configured wallet address, as before.continue()always sends the configured wallet address, as before.jwkclient on an interactive request (the spec allows it only for non-interactive grants), ajwkwith a private key (d), and anxvalue that is not 43 base64url characters.PendingGrantTransformercalledSimpleAccessTokenwith 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.subjectreturns a pending grant with an interaction URL.