feat: own the Origin install handshake on the adapter - #136
Merged
Conversation
Origin has no OAuth2 - installs are approved on Cursor and confirmed by an EdDSA-signed receipt - so consumers were left modelling the handshake as an OAuth2 client, duplicating this adapter's Ed25519 and JWKS machinery to do it. The adapter now owns its own protocol: - getInstallUrl() builds the install-page URL, with the empty-scope app-metadata quirk documented in one place - verifyReceipt() verifies a receipt JWT against the published JWKS and returns its claims - getSigningKeys() hands out the active Ed25519 keys in the shape validateWebhookEvent() accepts, so webhook consumers stop fetching the JWKS by hand Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Contributor
Greptile SummaryThe PR adds an Origin-owned installation handshake, including install URL construction, EdDSA receipt verification, and cached JWKS access.
Confidence Score: 4/5The signing-key cache recovery path should be fixed before merging because valid installation receipts can be rejected after key rotation or a transient JWKS failure. Receipt verification always consults the existing per-instance JWKS cache and has no refresh-on-unknown-key path, despite the adapter explicitly supporting that rotation pattern for webhook keys. Files Needing Attention: src/VCS/Adapter/Git/Origin.php Important Files Changed
Prompt To Fix All With AI### Issue 1
src/VCS/Adapter/Git/Origin.php:415
**Stale JWKS blocks valid receipts**
If an `Origin` instance is reused across signing-key rotation or after an empty JWKS response, `signingKey()` only consults the indefinitely cached key set and never refreshes it, causing valid installation callbacks to be rejected as signed with an unknown key for the remainder of the instance's lifetime.
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.Reviews (1): Last reviewed commit: "feat: own the Origin install handshake o..." | Re-trigger Greptile |
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.
What does this PR do?
Origin has no OAuth2 — installs are approved on Cursor and confirmed by an EdDSA-signed installation receipt, with no authorization-code exchange. That left consumers (Appwrite) modelling the handshake as an
OAuth2client subclass: ~330 lines whose only live methods were building the install URL and verifying the receipt, wrapped in deadgetTokens()/getUser*()ceremony and a duplicate of this adapter's Ed25519/JWKS machinery.The adapter now owns its own protocol, next to the webhook verification that already trusts the same signing keys:
getInstallUrl(string $appId, array $scopes = [], string $redirectUri = '', string $state = ''): string— the install-page URL on{webEndpoint}/apps/install, including the quirk that an empty scope list must sendsource=app-metadata(the install page refuses an explicit empty list).verifyReceipt(string $receipt, string $appId): array— full receipt verification: JWT structure,EdDSAalgorithm, theorigin-installation-receipt+jwtmedia type (tolerated absent, never another token kind), signature against the published JWKS bykid, issuer, audience,exp/nbf/iatwith 60s leeway, and a requiredsub. Returns the claims.getSigningKeys(bool $refresh = false): array— the active Ed25519 keys as base64url raw material, the shapevalidateWebhookEvent()accepts, so webhook consumers can stop hand-fetching the JWKS;$refreshsupports the rotation-retry pattern.JWKS entries are fetched through the adapter's own
call()and memoized per instance; key resolution reuses the existinged25519PublicKey().First consumer: appwrite/appwrite#13259, which deletes its
Auth\OAuth2\Cursorclass in favor of these methods (follow-up there once this is tagged).Test Plan
Credential-free, following the existing webhook-test pattern (locally generated sodium keys; a fixture subclass supplies the JWKS so the real verification path runs without network):
testGetInstallUrl/testGetInstallUrlWithoutScopesReadsAppMetadatatestVerifyReceipt— happy path returnssub/state/namespace_idtestVerifyReceiptRejections— not-a-JWT, wrong algorithm, wrong token type, unknownkid, wrong audience, wrong issuer, expired, missingsub, signed by a different keytestGetSigningKeysOriginTest: 17 tests, 89 assertions, green. Pint and PHPStan (level 8, src + tests) pass.
🤖 Generated with Claude Code