Sourcetree shows generic Authentication failed error for expired personal access token
0 reputation · 29 Jun 2021, 18:43 UTC
0 reputation · 29 Jun 2021, 18:43 UTC
When a personal access token (PAT) used for HTTPS authentication in Atlassian Sourcetree expires, the application shows a generic Authentication failed dialog without indicating that the credential has expired.
The goal is to determine whether Sourcetree can be configured or extended to surface a more specific error (token expired) so users can take timely action, given that Sourcetree relies on the operating system's keychain or Git credential helper and does not automatically refresh OAuth tokens.
Is there a setting, environment variable, or credential‑helper behavior that triggers a distinct error message for expired PATs? Does Sourcetree expose any internal log or diagnostic output that differentiates expiration from other authentication failures? Are there known work‑arounds that preserve least‑privilege scopes while providing clearer expiry feedback?
34275 reputation · 29 Jun 2021, 18:54 UTC
No. As of current Sourcetree releases there is no setting, environment variable, or credential-helper option that makes Sourcetree display a distinct "token expired" message. Sourcetree delegates HTTPS authentication to the underlying Git client and the OS credential store (Keychain on macOS, Credential Manager on Windows), and simply forwards whatever Git reports. When a PAT is expired, the server returns the same HTTP 401 it returns for any invalid credential, so Sourcetree has nothing more specific to show.
Two layers collapse the detail before it reaches the dialog:
remote: Invalid access token), but the HTTP status itself does not distinguish "expired" from "wrong password" or "insufficient scope."This is confirmed behavior of the credential flow, not a misconfiguration on your machine.
Sourcetree's log (Help → Show Log, or View → Show Log depending on platform/version) records the raw Git command output. You will see the 401 failure there, but Sourcetree does not annotate it as an expiration. The log is useful for confirming which remote and credential helper were involved, not for diagnosing token state.
Run the same operation from a terminal, which exposes the server's full message:
git ls-remote https://gitlab.example.com/group/repo.gitIf the host prints something like remote: Invalid access token, the token is dead rather than, say, a scope or account problem. You can also query the host's API directly:
curl -i -H "PRIVATE-TOKEN: $TOKEN" https://gitlab.example.com/api/v4/userA 401 here confirms the token itself is rejected. Avoid pasting the token into shared logs or shell history on multi-user systems.
/api/v4/user.read_repository/write_repository) and a calendar reminder before its expiry date. When it expires, replace it through Sourcetree's credential prompt or by deleting the entry in Keychain/Credential Manager so Sourcetree re-prompts.Exact dialog text and log location vary by Sourcetree version and OS, and host-specific 401 body messages change over time. Verify against your Sourcetree release and Git host before scripting around the messages above.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.