{"record":{"id":"27bfcf118cce13e6","repo":"git-ecosystem/git-credential-manager","slug":"failed-to-resolve-username-http-result-statusco","errorCode":null,"errorMessage":"Failed to resolve username. HTTP: {result.StatusCode}","messagePattern":"Failed to resolve username\\. HTTP: (.+?)","errorType":"exception","errorClass":"Trace2Exception","httpStatus":null,"severity":"error","filePath":"src/Atlassian.Bitbucket/BitbucketHostProvider.cs","lineNumber":376,"sourceCode":"                _context.Trace.WriteLine(\"Credential was not erased.\");\n            }\n\n            return Task.CompletedTask;\n        }\n\n        #endregion\n\n        #region Private Methods\n\n        private async Task<string> ResolveOAuthUserNameAsync(GitRequest request, string accessToken)\n        {\n            RestApiResult<IUserInfo> result = await _restApiRegistry.Get(request).GetUserInformationAsync(null, accessToken, isBearerToken: true);\n            if (result.Succeeded)\n            {\n                return result.Response.UserName;\n            }\n\n            throw new Trace2Exception(_context.Trace2,\n                $\"Failed to resolve username. HTTP: {result.StatusCode}\");\n        }\n\n        private async Task<string> ResolveBasicAuthUserNameAsync(GitRequest request, string username, string password)\n        {\n            RestApiResult<IUserInfo> result = await _restApiRegistry.Get(request).GetUserInformationAsync(username, password, isBearerToken: false);\n            if (result.Succeeded)\n            {\n                return result.Response.UserName;\n            }\n\n            throw new Trace2Exception(_context.Trace2,\n                $\"Failed to resolve username. HTTP: {result.StatusCode}\");\n        }\n\n        private async Task<bool> ValidateCredentialsWork(GitRequest request, ICredential credentials, AuthenticationModes authModes)\n        {\n            if (_context.Settings.TryGetSetting(","sourceCodeStart":358,"sourceCodeEnd":394,"githubUrl":"https://github.com/git-ecosystem/git-credential-manager/blob/e8ce762cd04b4100ae637b5fbf39ef9d0a96561e/src/Atlassian.Bitbucket/BitbucketHostProvider.cs#L358-L394","documentation":"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.","triggerScenarios":"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.","commonSituations":"OAuth token revoked in Bitbucket settings; rate limiting (429); corporate proxy blocking api.bitbucket.org; Bitbucket API outage.","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"],"exampleFix":"// before\n// 401 from /2.0/user with stale token\n// after\n// re-authenticate: git credential reject <<url>> then git pull to trigger fresh OAuth flow","handlingStrategy":"retry","validationCode":"using var ping = new HttpClient();\nvar ok = (await ping.GetAsync(\"https://api.bitbucket.org/2.0/user\")).StatusCode != HttpStatusCode.Unauthorized; // probe connectivity/creds\nif (!ok) await RefreshOAuthTokenAsync();","typeGuard":"bool IsRetryableStatus(HttpStatusCode s) => s == HttpStatusCode.RequestTimeout || (int)s == 429 || (int)s >= 500;","tryCatchPattern":"try { var cred = await provider.GetCredentialAsync(input); }\ncatch (Trace2Exception ex) when (ex.Message.Contains(\"Failed to resolve username\"))\n{ gitCredentialReject(uri); /* force fresh OAuth next attempt */ }","preventionTips":["Keep OAuth tokens fresh; re-authenticate when revoked","Verify proxy settings allow api.bitbucket.org","Monitor Bitbucket status/rate limits before bulk operations"],"tags":["http","oauth","rest-api","bitbucket","token"],"backgroundTag":"http-error-response","analyzedSha":"e8ce762cd04b4100ae637b5fbf39ef9d0a96561e","analyzedAt":"2026-09-11T17:15:08.753Z","contentChangedAt":"2026-09-11T17:15:08.753Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}