Cloning a private Project repository using OAuth2 token

How do I use OAuth2 token to clone a repository, when that project is set to private?

I have an OAuth2 access token, which has the scopes read_api read_repository. It works on the API calls, so it is not expired.

I have tried the following command on a private project I own:

git clone 'https://oauth2:9575eb4457............de69@gitlab.com/rok.lenarcic/rok-s-project.git'

And I get the response:

Cloning into 'rok-s-project'...
remote: HTTP Basic: Access denied
fatal: Authentication failed for 'https://gitlab.com/rok.lenarcic/rok-s-project.git/'

How do I use my OAuth2 token to clone private repositories? Are the scopes I use correct?

Replying to my own post. The solution is to use api token scope. That works, but it is a bit unfortunate that I need to request read/write access to package registry, container registry, groups, projects just to clone the repository.

1 Like