Skip to content

Connect GitHub with no setup on your own computer - #143

Open
ponytojas wants to merge 2 commits into
mainfrom
task/github-connect-in-local
Open

ponytojas wants to merge 2 commits into
mainfrom
task/github-connect-in-local

Conversation

@ponytojas

Copy link
Copy Markdown
Collaborator

Stacked on #139 (it reuses that PR's loopback check and browser opener). Retarget to main once #139 merges.

In the Mac app, Connect GitHub said "GitHub sign-in is not set up on this server (REFRACT_GITHUB_CLIENT_ID)": nobody can set that variable for the app.

Changes

  • refract local, and so the Mac app, uses Refract's own GitHub OAuth App (Ov23liYnkF9XAiPRni54, owned by Use-Refract, device flow, public client id, no secret) when REFRACT_GITHUB_CLIENT_ID is not set. Servers are unchanged: they still need their own app, or they show the existing "not set up" message.
  • On a server that listens on loopback, POST /api/github/device opens GitHub's device page in the browser itself and answers opened. This is the same reason as in Sign in with ChatGPT from Settings when Refract runs on this computer #139: WKWebView drops a window.open made after a request. The page calls window.open only when the server didn't open it. The server opens the address only if it is on the configured GitHub web origin, because it comes from GitHub's answer and the opener would follow any scheme.
  • onThisComputer(addr) is shared by both features.
  • Docs: README "Connect GitHub" and CHANGELOG.

Checks

  • go test ./cmd/refract/ ./internal/github/ and go vet pass. A new test covers opening GitHub's page, refusing a non-GitHub address, no opener on a server elsewhere, and a failed open.
  • tsc passes and the i18n test passes.
  • make mac builds. Still to check by hand in the app: Settings → Integrations → Connect opens GitHub, and the code completes the connection.

Base automatically changed from task/g1-sign-in-with-chatgpt-from-settings-when to main November 26, 2026 13:47

@Lorena-J Lorena-J left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The built-in GitHub configuration makes connecting from the Mac app much simpler. I’d request one change before merging. Please scope native browser opening to local launches so users on self-hosted instances behind a reverse proxy can still open GitHub from their own browser. The web build and targeted GitHub Go tests passed. Live GitHub authorization in the Mac app still needs a manual check.

Comment thread cmd/refract/main.go
if id := cmp.Or(os.Getenv("REFRACT_GITHUB_CLIENT_ID"), opts.githubClientID); id != "" {
ra.github = &github.Client{HTTP: outbound, ClientID: id, Web: "https://github.com", API: "https://api.github.com"}
}
if onThisComputer(ln.Addr()) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The documented Caddy and nginx setups also proxy to a loopback listener. In that setup, clicking Connect GitHub can launch the browser on the server and return opened: true, so the user has to open GitHub manually from the link in Settings. Could we enable the native browser opener only when Refract is started with refract local, including from the Mac app?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants