Migrate GitHub integration to Vercel Connect#900
Open
blurrah wants to merge 2 commits into
Open
Conversation
Replace the manually-registered GitHub App with a Vercel Connect GitHub connector. Installation tokens are exchanged at runtime via @vercel/connect getToken (app subject), user tokens via user-subject exchange keyed by the Connect OIDC sub better-auth stores as accounts.accountId, and webhooks arrive through Connect trigger forwarding verified with Vercel OIDC instead of an HMAC secret. Removes GITHUB_APP_ID, GITHUB_APP_PRIVATE_KEY, NEXT_PUBLIC_GITHUB_CLIENT_ID, GITHUB_CLIENT_SECRET, and GITHUB_WEBHOOK_SECRET in favor of a single GITHUB_CONNECTOR uid. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
Review the following changes in direct dependencies. Learn more about Socket for GitHub.
|
Verified against a live connector (github/test-open-agents): getToken accepts GitHub's numeric installation id, scopes/resources do not narrow app tokens, and tokens expire after ~15 minutes. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
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
Replaces the manually-registered GitHub App with a Vercel Connect GitHub connector. Vercel creates and manages the GitHub App; the app exchanges short-lived tokens at runtime and stores no GitHub credentials —
GITHUB_APP_ID,GITHUB_APP_PRIVATE_KEY,NEXT_PUBLIC_GITHUB_CLIENT_ID,GITHUB_CLIENT_SECRET, andGITHUB_WEBHOOK_SECRETare all removed in favor of a singleGITHUB_CONNECTOR(UID likegithub/test-open-agentsorscl_…id — both work).What changed
lib/github/installation-tokens.ts, replaceslib/github/app.ts):mintInstallationToken/withScopedInstallationOctokitkeep their shape but are backed bygetToken({subject: {type: "app"}, installationId}). The mint-and-revoke-per-use pattern is gone — Connect tokens are cached/shared by the SDK, so revoking one would break concurrent callers; validity buffers (5 min default, 10 min for sandbox clones) guarantee remaining lifetime instead.lib/auth/github-provider.ts): the Better Authgithubsocial provider becomes agenericOAuthprovider via@vercel/connect/betterauth(link-only,disableImplicitSignUp). Client link calls move fromlinkSocialtooauth2.linkwith anerrorCallbackURL.lib/github/token.ts): the token better-auth stores is a Connect-issued token, not a raw GitHub token, sogetUserGitHubTokennow exchanges viagetToken({subject: {type: "user", id: accounts.accountId}})(the Connect OIDCsub). Disconnect and the admin revoke-all action now revoke the Connect grant (revokeUserGitHubGrant) instead of calling GitHub's application-token API.lib/github/webhook-verification.ts):/api/github/webhooknow accepts Connect trigger-forwarded events verified via Vercel OIDC (createConnectWebhookVerifier) instead of HMAC. Handlers (pull_requeststatus/archive,installation*sync) are unchanged.apps/webdrops@octokit/auth-app;@vercel/connectadded.Setup status
Connector
github/test-open-agentsis created, attached to theopen-agentsproject, andGITHUB_CONNECTORis set in the project env. Remaining: repointNEXT_PUBLIC_GITHUB_APP_SLUGto the Connect app's github.com slug, and consider narrowing the connector's permissions in Advanced settings (it currently grants 12 write-level permissions; the app needs Contents R/W, Pull requests R/W, Metadata RO, Checks RO) plus enabling thepull_request/installationtrigger event types with trigger path/api/github/webhook.Verified against the live connector ✅
getTokenaccepts GitHub's numeric installation id asinstallationId(and returns it ingetTokenResponse, with granted permissions inmetadata) — no id-mapping column needed.api.github.comas installation tokens.scopes/resourcesare accepted but do not narrow GitHub app tokens — the trust boundary staysverifyRepoAccess(user perms ∩ installation coverage), with a single seam ininstallation-tokens.tsto enable narrowing if Connect adds it.UserAuthorizationRequiredError, which maps to the existing reconnect UX.Still to verify on a preview deploy
oauth2.link→ Connect consent → account row with Connectsub) and thatGET /user/installationsworks with the exchanged user token.pull_request/installationtrigger event types actually forward in beta (fallbacks: lazy PR-status refresh on session view; installation sync already runs on everyconnection-statuspoll).app/callbackstays dead-but-harmless, lazy sync covers post-install state).Cutover (breaking for existing users)
This is a hard cutover: everyone must re-link GitHub and re-install the new app via the existing reconnect UI. Old
accountsrows forproviderId='github'must be deleted manually — better-auth matches accounts by(accountId, providerId), and the Connect subject id differs from the old GitHub numeric id, so stale rows would shadow new grants forever. Runapps/web/scripts/connect-github-cutover.sqlagainst prod at deploy time (deliberately not an auto-running migration).Testing
pnpm run cigreen (format, lint, typecheck, bun tests incl. rewrittentoken.test.tsand updated route/auto-commit/auto-pr mocks).VERCEL_OIDC_TOKEN(tokens used in-process only, never logged).🤖 Generated with Claude Code