How to access bitbucket using app password
Asked Answered
D

7

110

I have created an app password as explained here

But now, how do I access the repository using this app password?
What will be the url?
Can someone direct me to a page showing an example please?

The below is a code for github. How do I do it for bitbucket?

var githubToken = "[token]";
var url = "https://github.com/[username]/[repository]/archive/[sha1|tag].zip";
var path = @"[local path]";


using (var client = new System.Net.Http.HttpClient())
{
    var credentials = string.Format(System.Globalization.CultureInfo.InvariantCulture, "{0}:", githubToken);
    credentials = Convert.ToBase64String(System.Text.Encoding.ASCII.GetBytes(credentials));
    client.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Basic", credentials);
    var contents = client.GetByteArrayAsync(url).Result;
    System.IO.File.WriteAllBytes(path, contents);
}

Update

Go to Personal Settings and then App Passwords as shown below.

Create Bitbucket App Password

Dentist answered 6/10, 2016 at 3:22 Comment(2)
You ask about Bitbucket, but your code references githubToken and https://github.com/. Which system are you actually trying to use?Tessellation
@Chris, github is only an example : The below is a code for github. How do I do it for bitbucket?Westland
E
111

You can perform this request as follows:

curl -u "walery2iq:<appPassword>" "https://api.bitbucket.org/2.0/repositories/[yourRepo]"

Important thing here - use your username, not e-mail address. Important because for login on bitbucket itself you are using e-mail and not username :D

You can find your username here:

Settings -> Account settings -> Username

See picture.

Use this username - not your mail address

Edora answered 5/7, 2017 at 17:51 Comment(1)
Username, not email address, was the key for me using the Bitbucket import UI. Thanks!Chaldron
T
135

Since the question was "how do I access the repository" - maybe this is useful for somebody:
You can also use a Bitbucket "App Password" to use Git over HTTPS.

git clone https://USERNAME:[email protected]/OWNER/REPO.git

(Or, if you want to avoid storing the password in plaintext:
Omit :APP_PASSWORD in the URL above, and just provide the App Password when prompted by Git.)

This may be useful for CI (although Git over SSH might be better).

Troubadour answered 14/6, 2020 at 21:16 Comment(3)
IF you already cloned repository, use this git remote set-url origin https://USERNAME:[email protected]/OWNER/REPO.gitAlroi
ok. It really isn't obvious. You need to set your Remote URL/Path in SourceTree Settings as follows https://<user-name>:<app-password>@bitbucket.org/path-to-source-master/src/master/ The user name is the main account user name, which is found under Bitbucket profile settings (Username) under Account Settings at bitbucket.org/account/settings The app password is set in bitbucket.org/account/settings/app-passwordsAromatize
Seems like this method is exposing the password in clear text..Marmite
E
111

You can perform this request as follows:

curl -u "walery2iq:<appPassword>" "https://api.bitbucket.org/2.0/repositories/[yourRepo]"

Important thing here - use your username, not e-mail address. Important because for login on bitbucket itself you are using e-mail and not username :D

You can find your username here:

Settings -> Account settings -> Username

See picture.

Use this username - not your mail address

Edora answered 5/7, 2017 at 17:51 Comment(1)
Username, not email address, was the key for me using the Bitbucket import UI. Thanks!Chaldron
H
76

You need to create your "app password" on bitbucket console. Under your Avatar ->Personal Settings ->Access Management ->App Password. Create app password and note it down.

Once done, open your git bash and set the remote origin using -

git remote set-url origin https://<Your_Account_Name>:<App_Password>@bitbucket.org/<Your_Account_Name>/<Repo_Name>.git
Hasbeen answered 31/1, 2022 at 3:12 Comment(2)
In the last part, you are not required to give Account_name again instead need to provide a path for the repo. bitbucket.org/OWNER/REPO.gitKristopherkristos
this is the one that works for me. but maybe just a little correction: it should be https://<your_username>:<app_password>@bitbucket.org/...Vulcan
F
20

If you have a 2-step verification I was able to clone but not to make a push. This worked for me using git instead of curl:

git push https://<username>:<GENERATED-APP-PASS>@bitbucket.org/<username>/<repo>.git

Generate an app password at https://bitbucket.org/account/admin/app-passwords

Fenella answered 9/4, 2021 at 10:9 Comment(0)
A
8
git remote set-url origin https://[app-label]:[app-password]@bitbucket.org/[your-repo].git
Autumn answered 27/1, 2022 at 8:17 Comment(1)
Did not work. Says invalid credentials after trying to push. Kunal Keshari solution worked. You need Account_Name instead of app-label. And you need to repeat it after bitbucket.org/Perforate
N
1

Git uses libcurl under the hood so one might keep password in ~/.netrc file:

machine bitbucket.org login USER password PAZZ

and avoid leaking password to shell history:

git clone https://[email protected]/$WORKSPACE/$REPO.git
Nunatak answered 21/4, 2022 at 10:16 Comment(0)
T
1

This worked for me, check use credential helper from git settings. That is, preferences-> version control-> To git -> use credential helper

Tudela answered 25/4, 2022 at 6:54 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.