使用项目访问令牌来克隆一个私有的GitLab存储库。

huangapple go评论68阅读模式
英文:

Using project access token to clone a private gitlab repository

问题

我有一个托管在gitlab.com上的私有仓库。我已经创建了一个具有read_repository范围的项目访问令牌。我的意图是任何具有该项目访问令牌的用户都可以克隆仓库。

我正在执行以下操作:

git clone https://xyz@gitlab.com/user/repo.git

当要求输入密码时,我输入了项目访问令牌,但收到以下提示:

Cloning into 'repo'...
Password for 'https://xyz@gitlab.com': 
remote: You are not allowed to download code from this project.
fatal: unable to access 'https://gitlab.com/user/repo.git/': The requested URL returned error: 403

我尝试创建了多个具有除read_repository之外多个范围的项目访问令牌,但仍然遇到相同的错误。我还尝试直接在克隆命令中使用项目访问令牌:

git clone https://xyz:MY_ACCESS_TOKEN@gitlab.com/user/repo.git

但仍然收到相同的错误。

澄清

我创建的所有项目访问令牌都设置了一个月后过期的日期。xyz字符串据我了解是无关紧要的,因为它是用户名的占位符。根据gitlab文档,似乎这可以是任何非空字符串。

英文:

I have a private repository that is hosted on gitlab.com. I've created a project access token with read_repository scope. The intention is that any user with the project access token can clone the repository.

I'm issuing:

git clone https://xyz@gitlab.com/user/repo.git

and when prompted for my password, I enter the project access token, but am told:

Cloning into 'repo'...
Password for 'https://xyz@gitlab.com': 
remote: You are not allowed to download code from this project.
fatal: unable to access 'https://gitlab.com/user/repo.git/': The requested URL returned error: 403

I've tried creating a number of additional project access tokens with multiple scopes in addition to read_repository, but get the same error. I've also tried cloning using the project access token directly in the clone:

git clone https://xyz:MY_ACCESS_TOKEN@gitlab.com/user/repo.git

but get the same error.

Clarifications

All project access tokens I've created have an expiry date set to a month from now. The xyz string is, to my understanding, irrelevant, since it's a placeholder for the username. From the gitlab documentation, it seems this can be any non-empty string.

答案1

得分: 1

"What does the xyz stands for ?" => "xyz 是什么的缩写?"
"Are you the owner of the repository / do you have permissions ?" => "你是仓库的所有者/是否有权限?"

--- "What you actually want to do is add the oauth2 protocol before the actual token" => "实际上你想要做的是在实际令牌之前添加 oauth2 协议"
git clone https://oauth2:MY_ACCESS_TOKEN@gitlab.com/user/repo.git

"If it doesnt help, try executing a rest api using this token to make sure it is valid." => "如果这不起作用,请尝试使用此令牌执行一个 REST API 来确保它有效。"

"Try Referring this post for further investigating." => "尝试参考 此帖子 进一步调查。"
1: https://stackoverflow.com/questions/42148841/github-clone-with-oauth-access-token?rq=2

英文:

What does the xyz stands for ?
Are you the owner of the repository / do you have permissions ?

--- What you actually want to do is add the oauth2 protocol before the actual token

git clone https://oauth2:MY_ACCESS_TOKEN@gitlab.com/user/repo.git

If it doesnt help, try executing a rest api using this token to make sure it is valid.

Try Referring this post for further investigating.

答案2

得分: 1

在我的情况下,问题是我们无法在私有仓库中使用“访客”令牌,即使权限是403也不行。使用“报告者”或其他任何都可以。

英文:

In my case, the issue was that we can not use "Guest" tokens in private repos even with permissions will be 403. Using "Reporter" or any other works

huangapple
  • 本文由 发表于 2023年5月10日 17:34:06
  • 转载请务必保留本文链接:https://go.coder-hub.com/76216890.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定