Git commands failing with URL rejected when using HTTP access tokens as Basic Auth

Still need help?

The Atlassian Community is here for you.

Ask the community


Platform Notice: Data Center - This article applies to Atlassian products on the Data Center platform.

Note that this knowledge base article was created for the Data Center version of the product. Data Center knowledge base articles for non-Data Center-specific features may also work for Server versions of the product, however they have not been tested. Support for Server* products ended on February 15th 2024. If you are running a Server product, you can visit the Atlassian Server end of support announcement to review your migration options.

*Except Fisheye and Crucible

Summary

Performing git clone with access token as Basic Auth returns the following error:

λ: git clone http://x-token-auth:BBDC-MjAzMjgzMTU0NzU1Oix/XD3JWM30a7uPcI4xZ2nLnIia@localhost:7990/scm/project/repo.git
Cloning into 'repo'...
fatal: unable to access 'http://x-token-auth:BBDC-MjAzMjgzMTU0NzU1Oix/XD3JWM30a7uPcI4xZ2nLnIia@localhost:7990/scm/project/repo.git/': URL rejected: Port number was not a decimal number between 0 and 65535

OR

λ: git clone 'http://x-token-auth:BBDC-MjAzMjgzMTU0NzU1Oix/XD3JWM30a7uPcI4xZ2nLnIia@localhost:7990/scm/project/repo.git'                             
Cloning into 'repo'...
fatal: unable to access 'http://x-token-auth:BBDC-MjAzMjgzMTU0NzU1Oix/XD3JWM30a7uPcI4xZ2nLnIia@localhost:7990/scm/project/repo.git/': URL rejected: Port number was not a decimal number between 0 and 65535

Environment

  • Any version of Bitbucket Data Center that supports access tokens as Basic Auth.

Diagnosis

The same access token works fine when used as a Bearer token:

λ: git clone -c http.extraHeader='Authorization: Bearer BBDC-MjAzMjgzMTU0NzU1Oix/XD3JWM30a7uPcI4xZ2nLnIia' http://localhost:7990/scm/project/repo.git
Cloning into 'repo'...
warning: You appear to have cloned an empty repository.

Cause

This is because the access token contains characters that breaks the URL syntax. The token will need to be URL encoded.

Solution

URL encode the token using the following command:

λ: echo -n "BBDC-MjAzMjgzMTU0NzU1Oix/XD3JWM30a7uPcI4xZ2nLnIia" | jq -sRr @uri
BBDC-MjAzMjgzMTU0NzU1Oix%2FXD3JWM30a7uPcI4xZ2nLnIia

And then use the encoded token within the git clone command:

λ: git clone http://x-token-auth:BBDC-MjAzMjgzMTU0NzU1Oix%2FXD3JWM30a7uPcI4xZ2nLnIia@localhost:7990/scm/project/repo.git
Cloning into 'repo'...
warning: You appear to have cloned an empty repository.

For a oneliner:

λ: git clone http://x-token-auth:$(echo -n "BBDC-MjAzMjgzMTU0NzU1Oix/XD3JWM30a7uPcI4xZ2nLnIia" | jq -sRr @uri)@localhost:7990/scm/project/repo.git
Cloning into 'repo'...
warning: You appear to have cloned an empty repository.


Last modified on Jan 13, 2025

Was this helpful?

Yes
No
Provide feedback about this article
Powered by Confluence and Scroll Viewport.