如何使用app密码访问bitbucket

时间:2016-10-06 03:22:21

标签: bitbucket

我已根据here

的说明创建了应用密码

但是现在,如何使用此应用密码访问存储库?
什么是网址?
有人可以指示我到一个显示示例的页面吗?

以下是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);
}

3 个答案:

答案 0 :(得分:18)

您可以按如下方式执行此操作:

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

重要的是 - 使用您的用户名,而不是电子邮件地址。 重要的是因为登录bitbucket本身你使用的是电子邮件,而不是用户名:D

您可以在此处找到您的用户名:

  

设置 - &gt;帐户设置 - &gt;用户名

见图。

Use this username - not your mail address

答案 1 :(得分:9)

由于问题是“我如何访问存储库”-也许这对某人有用:
您还可以使用Bitbucket“应用密码”通过HTTPS使用Git。

git clone https://USERNAME:APP_PASSWORD@bitbucket.org/OWNER/REPO.git

(或者,如果要避免以明文形式存储密码,则:
在上面的网址中省略:APP_PASSWORD,仅在Git提示时提供应用密码。)

这可能对CI有用(尽管通过SSH进行Git可能更好)。

答案 2 :(得分:2)

如果您有两步验证,我可以克隆但不能进行推送。这对我使用 git 而不是 curl 有用:

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

https://bitbucket.org/account/admin/app-passwords 生成应用密码

相关问题