git-ecosystem/git-credential-manager · error · Trace2Exception
Failed to resolve username. HTTP
Error message
Failed to resolve username. HTTP: {result.StatusCode} What it means
During OAuth flows, ResolveOAuthUserNameAsync calls the Bitbucket REST API (/user) with the access token to map the token to a username. If the API call fails (result.Succeeded false), the provider cannot identify the account and throws Trace2Exception with the HTTP status code.
Solutions
- Retry the git operation and re-run OAuth to obtain a fresh access token
- Verify network/proxy access to api.bitbucket.org (check HTTPS_PROXY settings)
- Check Bitbucket Cloud status / rate limits; retry after backoff
- Revoke and re-authorize GCM under Bitbucket account settings if the token is permanently invalid
Example fix
// before // 401 from /2.0/user with stale token // after // re-authenticate: git credential reject <<url>> then git pull to trigger fresh OAuth flow
Defensive patterns
Strategy: retry
Validate before calling
using var ping = new HttpClient();
var ok = (await ping.GetAsync("https://api.bitbucket.org/2.0/user")).StatusCode != HttpStatusCode.Unauthorized; // probe connectivity/creds
if (!ok) await RefreshOAuthTokenAsync(); Type guard
bool IsRetryableStatus(HttpStatusCode s) => s == HttpStatusCode.RequestTimeout || (int)s == 429 || (int)s >= 500;
Try / catch
try { var cred = await provider.GetCredentialAsync(input); }
catch (Trace2Exception ex) when (ex.Message.Contains("Failed to resolve username"))
{ gitCredentialReject(uri); /* force fresh OAuth next attempt */ } Prevention
- Keep OAuth tokens fresh; re-authenticate when revoked
- Verify proxy settings allow api.bitbucket.org
- Monitor Bitbucket status/rate limits before bulk operations
When it happens
Trigger: GetCredentialAsync OAuth path: GetUserInformationAsync(null, accessToken, isBearerToken:true) returns non-success — e.g. HTTP 401 (revoked/expired token), 403, or network failure producing an error status.
Common situations: OAuth token revoked in Bitbucket settings; rate limiting (429); corporate proxy blocking api.bitbucket.org; Bitbucket API outage.
Understand the failure class
Background: "API error: {status}" and "HTTP 401/403/404/429/5xx" errors: non-2xx HTTP responses explained — this error's family across 27 libraries.
Related errors
- Unencrypted HTTP is not recommended for Bitbucket.org…
- RemoteUri must be defined to generate Bitbucket DC OAuth2…
- Must specify at least one AuthenticationModes
- At least one AuthenticationModes must be supplied
- User cancelled credential prompt
AI-assisted analysis of git-ecosystem/git-credential-manager@e8ce762cd0 (2026-09-11).
Data as JSON: /api/errors/27bfcf118cce13e6.
Report an issue: GitHub.
Appendix: source
Thrown at src/Atlassian.Bitbucket/BitbucketHostProvider.cs:376
_context.Trace.WriteLine("Credential was not erased.");
}
return Task.CompletedTask;
}
#endregion
#region Private Methods
private async Task<string> ResolveOAuthUserNameAsync(GitRequest request, string accessToken)
{
RestApiResult<IUserInfo> result = await _restApiRegistry.Get(request).GetUserInformationAsync(null, accessToken, isBearerToken: true);
if (result.Succeeded)
{
return result.Response.UserName;
}
throw new Trace2Exception(_context.Trace2,
$"Failed to resolve username. HTTP: {result.StatusCode}");
}
private async Task<string> ResolveBasicAuthUserNameAsync(GitRequest request, string username, string password)
{
RestApiResult<IUserInfo> result = await _restApiRegistry.Get(request).GetUserInformationAsync(username, password, isBearerToken: false);
if (result.Succeeded)
{
return result.Response.UserName;
}
throw new Trace2Exception(_context.Trace2,
$"Failed to resolve username. HTTP: {result.StatusCode}");
}
private async Task<bool> ValidateCredentialsWork(GitRequest request, ICredential credentials, AuthenticationModes authModes)
{
if (_context.Settings.TryGetSetting(View on GitHub (pinned to e8ce762cd0)