Enterprise login sends requests to api.github.com instead of custom enterprise host (causes 401/"Error loading user info")
Summary of the issue:
For GitHub Enterprise logins, requests should target the configured enterprise API host (like https://github.test.com/api/v3), but requests for user info are incorrectly sent to api.github.com, resulting in a 401 and the UI showing "Error loading user info".
Impact:
- GitHub Enterprise accounts cannot load authenticated user info (breaks UI, produces 401 errors).
Log line:
2025-11-03T07:11:41.495964Z INFO get_gh_user:HTTP request: /Users/runner/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/reqwest-tracing-0.5.8/src/reqwest_otel_span_builder.rs:152: close time.busy=1.33ms time.idle=275ms account=Enterprise { username: "apurvasaraiya", host: "https://github.test.com/api/v3" } http.request.method=GET url.scheme=https server.address=api.github.com server.port=443 user_agent.original=gb-github-integration otel.kind="client" otel.name=GET otel.status_code="ERROR" otel.status_code="ERROR" http.response.status_code=401 http.response.status_code=401
How to reproduce:
- Add an enterprise GitHub account with a valid PAT and enterprise host (like
https://github.test.com/api/v3). - After login, the UI shows "Error loading user info",
- Check logs for requests to api.github.com (not the enterprise host).
Root cause:
- When fetching authenticated user info (in
get_gh_user), the code constructs the client usingGitHubClient::new(), which targets api.github.com. It should usenew_with_host_overridewhen GithubAccountIdentifier is Enterprise.
Proposed fix (needs team input):
Would updating the client construction in get_gh_user to mirror the pattern seen in storing enterprise PATs work as intended?
let gh = match account {
GithubAccountIdentifier::Enterprise { host, .. } => {
client::GitHubClient::new_with_host_override(&access_token, host)?
}
_ => client::GitHubClient::new(&access_token)?
};
- This would create the client with the correct host for enterprise accounts.
**Please advise if the proposed change would resolve the host targeting in all relevant code paths or if there are additional considerations for other enterprise API calls. I can submit a PR if this approach is confirmed (Perfect first issue for me). Thanks!
Thanks a lot for reporting, and even more for the investigation and for offering a fix!
Let me bring in @estib-vega who will be able to bring this to issue to completion.
Hey @apurvasaraiya, thanks so much for raising this and apologies for that.
Yes, the proposed fix would do the thing. If you want to fix this we'd be more than happy to take a contribution in! Just would depend whether you'd have time now to perform the fix? We're planning a release soon and I'd like this to be in that build.
@estib-vega, I'll provide the fix for above issue. I'm in the IST timezone. So it should not be a problem. Give me sometime, I'll raise the PR.
@estib-vega, I'll fix it. I'm in IST timezone. So it should not be a problem. Give me sometime, I'll raise the PR.
Thanks a bunch ❤️
@estib-vega, I've made the change. But not able to test it locally, running into some weird issue.
I have the below patch, Can you please merge verify, test and merge the changes as I have to log off:
file: crates/but-github/src/lib.rs
let gh = match account {
GithubAccountIdentifier::Enterprise { host, .. } => {
client::GitHubClient::new_with_host_override(&access_token, host)
.context("Failed to create GitHub Enterprise client")?
}
_ => client::GitHubClient::new(&access_token)
.context("Failed to create GitHub client")?,
};
Sorry for the inconvenience.
@estib-vega, I've made the change. But not able to test it locally, running into some weird issue.
I have the below patch, Can you please merge verify, test and merge the changes as I have to log off:
file: crates/but-github/src/lib.rs
let gh = match account { GithubAccountIdentifier::Enterprise { host, .. } => { client::GitHubClient::new_with_host_override(&access_token, host) .context("Failed to create GitHub Enterprise client")? } _ => client::GitHubClient::new(&access_token) .context("Failed to create GitHub client")?, }; Sorry for the inconvenience.
All good, thanks for checking that out either way!
Alright @apurvasaraiya this should be fixed on the next release. Hopefully we can get you GitButlering on Enterprise repos soon. Thanks again for raising this and do let me know if anything else is broken for you