3

My intent here is to use a "Personal Access Token" to be able to clone/pull from this repo (GitLab) in a java application. I just can't figure out how to get around this error.

Here is the code I have.

    String accessToken = conf.getString("accessToken");

    String uri = "https://gitlab-ci-token:" + accessToken + "@gitlab.com/dfurrer/cosmotronsBinaries.git";

    CredentialsProvider cp = new UsernamePasswordCredentialsProvider("PRIVATE-TOKEN", accessToken);
    git = Git.cloneRepository()
                    .setURI(uri)
                    .setCredentialsProvider(cp)
                    .setRemote("origin")
                    .setBranch("master")
                    .call();

I get his exception:

org.eclipse.jgit.api.errors.TransportException: https://gitlab-ci-token@gitlab.com/dfurrer/cosmotronsBinaries.git: git-upload-pack not permitted on 'https://gitlab-ci-token@gitlab.com/dfurrer/cosmotronsBinaries.git/'
Dave F
  • 116
  • 1
  • 5
  • 1
    Have you tried what I summarized here http://www.codeaffine.com/2014/12/09/jgit-authentication/ ? – Rüdiger Herrmann Jan 24 '18 at 20:13
  • Yes, that was the example that I worked from. I had it working using username/password but now using "Personal Access Token" I get his message. – Dave F Jan 24 '18 at 20:16

3 Answers3

2

I figured out the issue. I was creating a personal access key with read_user and read_registry only. Once I created a token with api permissions I'm able to clone.

Dave F
  • 116
  • 1
  • 5
  • Please can you share more info here in the answer? You were creating a personal access key in Git portal or where else? Thanks. – Atul Dec 11 '21 at 14:56
1

Jgit: use UsernamePasswordCredentialsProvider to authenticate with token, the username parameter may be token or use the owner name from repository url or be empty, the password parameter's value is your token value, the three style all work well in my way:

new UsernamePasswordCredentialsProvider("token","Personal Access Token")); 

new UsernamePasswordCredentialsProvider("the owner name of the repository","Personal Access Token")); 

new UsernamePasswordCredentialsProvider("","Personal Access Token"));
JustBaron
  • 2,319
  • 7
  • 25
  • 37
浪里冲
  • 11
  • 1
0

In Git config, try change to "JDK built-in" for HTTP client

refer: https://www.eclipse.org/forums/index.php/t/1104150/

Thang Le
  • 1,419
  • 1
  • 17
  • 25
  • Is that what we can do from STS or Eclipse? If yes, can you please tell how? Thanks. – Atul Dec 11 '21 at 14:54