Bitbucket Data Center: HTTP access token with Git, "URL rejected: Port number was not a decimal number" and "fatal: Authentication failed"
Git over HTTPS takes an HTTP access token as the password, and three details decide whether it works: the user name that goes with it, whether the token has characters that break a URL, and whether anything in front of the server still passes the sign-in on. The user name differs by kind of token: your own name for a personal token, x-token-auth for a project or repository token. This page is the Git side; the REST API's own refusals are on the "You are not permitted to access this resource" page.
What it looks like
fatal: unable to access 'https://x-token-auth:<token>@<bitbucket-host>/scm/<project>/<repository>.git/': URL rejected: Port number was not a decimal number between 0 and 65535
Password for 'https://<user>@<bitbucket-host>': fatal: Authentication failed
The same token works in the IDE: Pull Request Inbox for Bitbucket, a plugin for JetBrains IDEs, signs in to Data Center with a personal HTTP access token, kept in the IDE's password safe and sent only to that server.
1. Which user name
From Atlassian's page on HTTP access tokens:
- Personal token: use it in place of your password, with your own user name:
git clone https://<username>:<token>@<bitbucket-host>/scm/<project>/<repository>.git - Project or repository token, Basic authentication: the user name must be
x-token-auth. - Project or repository token, Bearer: skip the user name and send the token as a header (below). Atlassian says not to send a project or repository token with a user name in Basic authentication.
2. "URL rejected: Port number was not a decimal number": encode the token
Atlassian's article: any Data Center version that takes tokens as Basic authentication fails this way when the token contains characters that break URL syntax, for example a / in the token. The token has to be URL-encoded. With jq (the article's command):
echo -n "<token>" | jq -sRr @uri
Use the output in the URL, here as a repository token:
git clone https://x-token-auth:<encoded-token>@<bitbucket-host>/scm/<project>/<repository>.git
The same token, unencoded, works as a Bearer header, which is Atlassian's other answer:
git clone -c http.extraHeader="Authorization: Bearer <token>" https://<bitbucket-host>/scm/<project>/<repository>.git
(In Windows PowerShell, put the header in double quotes as above.) Atlassian lists a known problem with Bearer and Git LFS (BSERV-13613) and recommends Basic authentication for LFS.
3. "Authentication failed": the other causes
- The token itself. A token can have an expiry date, and Atlassian says that once created, the date cannot be changed: make a new token. A revoked token fails the same way. The page for personal tokens is Manage account → HTTP access tokens.
- An old password saved by Git. Atlassian's article on "Authentication failed" says Windows Credential Manager can hold stored Git passwords that make the sign-in fail: open Credential Manager in Control Panel and remove the Git entries for your server.
- The account is locked behind a CAPTCHA after too many wrong sign-ins: see "CAPTCHA required. Your Bitbucket account has been locked".
- A proxy in front of Bitbucket removes the sign-in. The same article names an Apache proxy with
RequestHeader unset Authorization: remove that line and restart the proxy. This is for whoever runs the proxy. - An
HTTP_PROXYvariable. The article says newer Git for Windows reads it; remove the variable, or see "Received HTTP code 407 from proxy". - First, the web interface. Atlassian's first check is whether the same user can sign in to Bitbucket in the browser.
In the IDE
Pull Request Inbox for Bitbucket, a plugin by Lesstep for JetBrains IDEs 2024.1 or later, works with Bitbucket Data Center 8.9 or later in beta. In Settings | Tools | Pull Request Inbox for Bitbucket you give the server and a token. With the user name empty, the token is sent as a Bearer token, which is what a project or repository token needs. With a user name, it goes in HTTP Basic. When Data Center refuses it, the plugin says that the token expired or was revoked, or that the user name is not the token's user, and that the user name should be left empty for a project or repository token. It does not send a refused token again until you change the token or user name, or press Refresh, because Data Center locks an account after repeated refused sign-ins. The IDE's own Git operations use Git's credentials, not this setting. The review inbox, diffs and discussions are free; approving, commenting and merging are Pro, with a 30-day trial.
Get it on JetBrains Marketplace
Sources
- HTTP access tokens (Atlassian)
- Git commands failing with URL rejected when using HTTP access tokens as Basic Auth (Atlassian)
- Git Commands Return Fatal: Authentication Failed (Atlassian)
Bitbucket and Atlassian are trademarks of Atlassian; IntelliJ IDEA is a trademark of JetBrains s.r.o. This page is not affiliated with or endorsed by Atlassian or JetBrains.
More: "You are not permitted to access this resource" · "CAPTCHA required" · Bitbucket Git remote URLs · 日本語