feat(developer): require a verified GitHub account to create an app - #945
Conversation
a0f2626 to
731c939
Compare
|
Local end to end testing of this flow is blocked by the hardcoded API base. Tracked separately in #947. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 731c93953f
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
01f1954 to
a30fc1c
Compare
|
CI caught a gap I had missed: Needs a repo variable before deploy: |
Adds the Connect GitHub flow to the create and edit forms: the portal stashes state and the return path, navigates to GitHub's authorize URL with one fixed callback (/apps), and validates state on return before carrying the code into the save request. Drops the VIP wall from the portal, since the worker replaces it with a per-user app cap. End-to-end verification is blocked on the trakt-workers PR that adds github_code handling and github_username to the response.
a30fc1c to
6108152
Compare
|
Addressed the codex review in
Also folded in a cleanup pass: the GitHub return path goes through the portal's existing
|
Summary
The developer portal side of requiring a verified GitHub account to create an API app. The VIP restriction on creating apps is removed at the same time.
The portal is its own OAuth redirect target. Clicking Connect GitHub stashes
{ state, returnPath }in sessionStorage and navigates to GitHub's authorize URL with one fixed callback of${location.origin}/apps. GitHub bounces back to/apps?code=...&state=...; that page validatesstate, stashes the code, and returns to the form it came from. The form then submits the code in the body it was already sending, and the API exchanges it.The portal never calls github.com itself, it only navigates there, so no CSP change is needed.
What changed
githubConnect.ts, new: builds the authorize URL, stashesstate, the return path and the in-progress form draft, validates on return, ignores unknown params. Returnsconnected/denied/invalidso a cancelled authorization is distinguishable from a tampered one. The return path goes through the portal's existingsafeReturnPathallowlist.routes/(portal)/apps/+page.svelte: handles the callback, validatesstate, bounces back to the return path. An error callback (the user pressing Cancel on GitHub) clears the pending state and renders a cancelled message instead of falling through to the app list.ApplicationForm.svelte: Connect GitHub on both create and edit. Unsaved form input survives the redirect, restored from the stashed draft when the form remounts with a code. Required on create only when the account has no linked GitHub identity yet. Once connected, further apps need no GitHub round trip, and the block shows the handle with a re-verify option instead.Applications.svelte: derives the account's linked handle from the apps list and passes it to the form, so a returning developer is not asked to reconnect.validateApplication.ts,applications.ts: carrygithub_codeinto the request, addgithub_usernameto the response schema.accountRequest.ts: the 403 copy no longer mentions VIP, plus a real message for a stale or reused code.Applications.svelteandApplicationPage.svelte: VIP gating removed, along with thevipprop it orphaned.create-an-app.md: states the requirement..env.example:PUBLIC_GITHUB_CLIENT_ID, read the same wayPUBLIC_TRAKT_CLIENT_IDalready is.The Connect GitHub block is on the edit form deliberately. Existing apps have no handle, and deleting and recreating is not an option because a new app means a new
client_id, which breaks every user already connected to it.Depends on
The API-side change that adds
github_codeon the request andgithub_usernameon the response, and makes the code required only on the first link. That side is merged-ready and has been verified live against production.Checks
deno fmt --check --config deno.jsonpassesdeno task format:svelte:checkpassesdeno task check: 363 files, 0 errors, 0 warningsdeno task test: 176 tests passedNot verified end to end
Local testing of the connect flow is not possible today, and a second GitHub OAuth App does not fix it.
src/lib/api/accountRequest.ts:14hardcodeshttps://api.trakt.tv${path}, so a local portal always calls the production API, which holds the production GitHub client secret. A code issued to a local OAuth App cannot be exchanged by it. Using the production client id locally fails earlier still, because GitHub rejects ahttp://localhost:5174/appsredirect against a registration forhttps://developer.trakt.tv/apps.So this is unit tested and will be smoke tested on production after deploy. The hardcoded API base is filed separately.
Note
PUBLIC_GITHUB_CLIENT_IDmust be set in the deploy environment, or Connect GitHub builds an authorize URL with an empty client id. The workflow now passes it to the verify and deploy builds, and the repository variable is set.