Repository navigation
Reuse GitHub CLI (gh) authentication as a GitHub account source
#16719
siegenthalerroger
started this conversation in
Ideas
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Problem
GitButler signs in to GitHub through its own OAuth App (the device flow in
crates/but-github/src/lib.rs, scoperepo). Orgs with OAuth App access restrictions turned on block that app until an owner approves it, and the restrictions are on by default for new orgs. My org's admin won't approve it, so I get no PRs, checks, reviews or stacks on org repos.The workaround is a personal access token that I create, scope, watch for expiry and rotate by hand. Org PAT policies can block that as well.
I already have a working
ghlogin for the same org, though. GitHub CLI is a privileged OAuth app, so org members can authorize it even when OAuth apps are restricted.What I tested
I pasted the output of
gh auth tokeninto GitButler's existing PAT sign-in. Everything works against my org's repos with no other changes.That makes sense: GitHub grants access based on the token, not on the program sending it, and GitButler doesn't check the token's scopes or which app issued it. A default
gh auth logingrantsrepo,read:organdgist, which covers thereposcope GitButler asks for.Proposal
Add a "GitHub CLI (gh)" account type to the desktop app and to
but config forge auth. GitButler would store just the host and username, and whenever it needs a token it would run:and use stdout as the bearer token.
I'd ask
ghevery time rather than copy the token once:gheach time (proposed)gh auth logout/refresh/switchghghcan issue 8-hour OAuth tokens and refreshes them insidegh auth token)ghstays the only ownerIf that's too much for a first pass, an "Import from GitHub CLI" button that passes
gh auth tokenoutput to the existingstore_pat/store_enterprise_patwould need no schema change. It has the problems in the left column, though.Prior art
Personally I've used:
auth.TokenForHostand hands it togithub-mcp-server.Others Claude found:
gh auth token --hostname <host>.Command::new("gh").args(["auth", "token"]).gh auth token -h <host>.GitButler should ask
ghfor the token and not readhosts.ymlor gh's keyring entry, since those are gh internals.All reactions