Fix UTexas EMU login redirect_uri mismatch and project creation failure#438
Conversation
✅ Deploy Preview for avannotate-staging ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
Co-authored-by: saracarl <708566+saracarl@users.noreply.github.com>
Clarify instructions for creating the OAuth App and add details about the settings location.
|
@copilot Ok. We've got the button for logging in to UT showing up, but after we login we see that the redirect takes us to: We're deployed to a staging URL that is different -- https://deploy-preview-438--avannotate-staging.netlify.app/ |
Build-time PUBLIC_REDIRECT_URL was always the canonical staging URL, so preview deployments (e.g. deploy-preview-438--…) sent a redirect_uri that wasn't registered in the OAuth App, producing GitHub's "Be careful!" warning. - SignInGitHub.tsx: replace PUBLIC_REDIRECT_URL with window.location.origin (safe because the component is client:only="react") - git-enterprise/index.ts: replace PUBLIC_REDIRECT_URL with new URL(request.url).origin for the post-auth redirect so the user lands back on the same deployment URL after sign-in
The "Be careful!" error was caused by the Two changes in commit
With these changes, as long as the current preview URL is registered in the OAuth App's callback list (which you've already done), the full flow should work without any changes to environment variables. |
GitHub Enterprise Managed Users cannot access repos outside their enterprise, so the standard AVAnnotate/project-template generate call fails with their token. - git-enterprise/index.ts: set auth-provider=utexas cookie on EMU login so the server can identify the session later - GitHub/index.ts: add optional templateOwner parameter to createRepositoryFromTemplate (defaults to GIT_REPO_ORG as before) - api/projects/[projectName]/index.ts: when auth-provider=utexas and UTEXAS_GIT_REPO_ORG is configured, use the enterprise copy of the template - .env.example / README.md: document UTEXAS_GIT_REPO_ORG and UTEXAS_GIT_REPO_PROJECT_TEMPLATE plus step-by-step fork instructions
Removed Astro Basics section and related content from README.
…t-creation-failure Improve GitHub API error logging for project creation
…terepositoryfromtemplate-function
…fromtemplate-function Log GitHub template repository generation request
### Motivation
- Support bimodal repository creation so public template generation remains unchanged while enterprise-managed orgs can use an enterprise template owner.
- Allow creating and representing GitHub `internal` repos for enterprise orgs even though the template API only accepts a `private` boolean.
- Improve GitHub failure observability by logging request ids and response bodies for template generation, visibility changes, and Pages operations.
### Description
- Added `src/lib/GitHub/config.ts` with helpers to parse `PUBLIC_GITHUB_ENTERPRISE_ORGS`/`GITHUB_ENTERPRISE_ORGS` and to resolve `GIT_REPO_ORG_ENTERPRISE` vs `GIT_REPO_ORG` for template owner selection.
- Updated `createRepositoryFromTemplate` in `src/lib/GitHub/index.ts` to pick the template owner via `getTemplateOwnerForDestinationOrg`, log the resolved generation URL and sanitized payload, and map `visibility` to the template API `private` boolean (treat `internal` as `private` initially).
- Extended `changeRepoVisibility` to accept a `boolean | RepoVisibility` and to PATCH either `{ private: ... }` or `{ visibility: 'internal' }` so internal visibility can be applied after template creation.
- Updated the front-end `NewProject` flow in `src/apps/NewProject/NewProject.tsx` to send `visibility: 'internal'` for non-private projects targeted at enterprise orgs and to keep `visibility: 'public'` for public orgs or `private` when requested.
- Enhanced the API handler in `src/pages/api/projects/[projectName]/index.ts` to call the visibility helper after template creation when `body.visibility === 'internal'`, to add `logGitHubFailure` logging (including `x-github-request-id` and response body) on failures, and to persist `visibility` into the project config while retaining `is_private` for backwards compatibility.
- Updated types in `src/types/api.ts` and `src/types/Types.ts` to allow `visibility: 'private' | 'public' | 'internal'` and to include `visibility` on the `Project` type.
### Testing
- Ran the project build and typecheck with `npm run build` (which runs `astro check` and the client/server build), and the build completed successfully with no type errors.
- Verified that `createRepositoryFromTemplate` composes and logs the resolved GitHub template URL and payload during local runs and that `changeRepoVisibility` can be called with `'internal'` to issue the appropriate PATCH request (failure cases are logged with request id and response body).
…imodal-github-project-creation
…b-project-creation Add GitHub enterprise/internal visibility support and switch project API to `is_private`
Added a function to log GitHub API failures with detailed information.

Two bugs in the UTexas EMU auth flow: the OAuth
redirect_uriwas hardcoded toPUBLIC_REDIRECT_URL(the canonical deployment URL), causing GitHub to reject it on preview deployments. After login, EMU tokens cannot accessAVAnnotate/project-templatebecause EMU accounts are isolated to their enterprise — making project creation fail with_repo_create_failed_.Changes
redirect_urimismatch (GitHub "Be careful!" warning)SignInGitHub.tsx— Replaceimport.meta.env.PUBLIC_REDIRECT_URLwithwindow.location.originwhen building the UTexas OAuth authorize URL. Safe because the component isclient:only="react".git-enterprise/index.ts— ReplacePUBLIC_REDIRECT_URLwithnew URL(request.url).originfor the post-auth redirect to/en/projects.EMU project creation failure
EMU tokens cannot call
POST /repos/AVAnnotate/project-template/generate— the template is outside their enterprise. The fix lets an enterprise-internal copy of the template be used instead.git-enterprise/index.ts— Set a secondauth-provider=utexascookie on successful EMU login so downstream server routes can identify the session.GitHub/index.ts— Add optionaltemplateOwnerparameter tocreateRepositoryFromTemplate; defaults toGIT_REPO_ORGfor no behavior change on non-EMU paths.api/projects/[projectName]/index.ts— Whenauth-provider=utexasandUTEXAS_GIT_REPO_ORGis set, use that org's copy of the template:.env.example/README.md— DocumentUTEXAS_GIT_REPO_ORGandUTEXAS_GIT_REPO_PROJECT_TEMPLATEwith step-by-step instructions to forkAVAnnotate/project-templateinto the UTexas enterprise and mark it as a template repository.Original prompt
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.