为什么个人访问令牌不适用于 Bitbucket REST API? [英] Why is Personal Access Token not working for Bitbucket REST API?
问题描述
TL/DR:(为什么)在 Bitbucket Web UI 中创建的名称/PAT 组合不适用于 Bitbucket REST API(或存储库克隆)?
我一直在阅读
PAT 名称为
test
",
实际上,您需要使用您的 BitBucket 用户帐户名称,而不是 PAT 名称作为用户名:
git clone https://username:@bitbucketserver.com/scm/projectname/teamsinspace.git
你也有语法(见这里)
git clonehttps://x-token-auth:{tokenHere}@bitbucket.org/yourRepoOwnerHere/RepoNameHere"
你可以使用gildas/git-credential-bitbucket
作为一种缓存令牌并自动重用它的方法
git credential-bitbucket 存储 <<EOM协议=https主机=bitbucket.org用户名=xxx客户 ID=yyy秘密=zzzgit 远程添加 bitbucket https://xxx@bitbucket.org/path/to/repo.gitgit config credential.helper bitbucket
TL/DR: (Why) does a name/PAT combination created in the Bitbucket web UI not work with Bitbucket REST API (or repo cloning)?
I've been reading various documentation on Bitbucket REST API and Personal Access Tokens, with the intent of using the latter when invoking the former.
All that I have read so far have said -- in more elaborative words -- that this is possible.
Following along, I created a Personal Access Token (PAT
) in the Bitbucket web UI.
Per the screenshot below (posted at the bottom, so as to not break up the text flow), the PAT
Name is "test", and let's say the PAT
value is Rzg4MGUyN4m4N9U3O1HQHO3ABJyp7xClvsan7sAmFEPy
Why, when I try to use this PAT
, do I get an "Authentication failed" error? For example:
user@bld_svr:~$ curl -L -u test:Rzg4MGUyN4m4N9U3O1HQHO3ABJyp7xClvsan7sAmFEPy -H "Content-Type: application/json" -X POST https://bitbucket.svr.com/rest/build-status/1.0/commits/5764bb32f80813b3bbcbf6496c113c1830c52bb0 -d '{"state":"INPROGRESS","key":"job_434","url":"http://bld_svr:8080//blue/organizations/jenkins/prj/detail/prj/434/pipeline"}'
{"errors":[{"context":null,"message":"Authentication failed. Please check your credentials and try again.","exceptionName":"com.atlassian.bitbucket.auth.IncorrectPasswordAuthenticationException"}]}
My readings have led me to believe that all that's necessary is:
- Creating the
PAT
in the Bitbucket UI - Using the Name/
PAT
combination the same as one would use username/password
Trying to debug the issue a little, this page, specifically, indicates that Name/PAT should be usable to git clone
repos. But that also fails:
$ git clone https://bitbucket.svr.com/scm/key/a_project.git
Cloning into 'a_project'...
Username for 'https://bitbucket.svr.com': test
Password for 'https://test@bitbucket.svr.com': # I typed in "Rzg4MGUyN4m4N9U3O1HQHO3ABJyp7xClvsan7sAmFEPy" here
fatal: Authentication failed for 'https://bitbucket.svr.com/scm/key/a_project.git/'
Can anyone give me the straight dope on the Bitbucket PAT
s and how they should be configured/used with Bitbucket REST API, and even just plain git clone
ing?
the PAT Name is "
test
",
Actually, you would need to use your BitBucket user account name, not the PAT name, as username:
git clone https://username:<token>@bitbucketserver.com/scm/projectname/teamsinspace.git
You also have the syntax (seen here)
git clone "https://x-token-auth:{tokenHere}@bitbucket.org/yourRepoOwnerHere/RepoNameHere"
And you can use gildas/git-credential-bitbucket
as a way to cache your token and reuse it automatically
git credential-bitbucket store <<EOM
protocol=https
host=bitbucket.org
username=xxx
clientid=yyy
secret=zzz
git remote add bitbucket https://xxx@bitbucket.org/path/to/repo.git
git config credential.helper bitbucket
这篇关于为什么个人访问令牌不适用于 Bitbucket REST API?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!