如何使用应用程序密码访问 bitbucket

我已经创建了一个应用程序密码解释 给你

但是现在,如何使用这个应用程序密码访问存储库呢?< br > 网址是什么?< br > 有没有人能给我一个示例页面?

下面是 github 的代码。我如何为 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);
}

更新

转到 个人设定,然后 应用程序密码,如下所示。

Create Bitbucket App Password

111630 次浏览

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

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:APP_PASSWORD@bitbucket.org/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).

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

git remote set-url origin https://[app-label]:[app-password]@bitbucket.org/[your-repo].git

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

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://$USER@bitbucket.org/$WORKSPACE/$REPO.git

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