通过jgit使用oauth2 access token操作gitlab api

github的写法(用户名都不用写):

UsernamePasswordCredentialsProvider provider = new UsernamePasswordCredentialsProvider("${access_token}","");
或者
UsernamePasswordCredentialsProvider provider = new UsernamePasswordCredentialsProvider("","${access_token}");

gitee、bitbucket的写法(要写用户名):

UsernamePasswordCredentialsProvider provider = new UsernamePasswordCredentialsProvider("${username}","${access_token}");

gitlab的写法(注意下面的"oauth2"都是"oauth2"字面量):

UsernamePasswordCredentialsProvider provider = new UsernamePasswordCredentialsProvider("oauth2","${access_token}");

Git git2 = Git.cloneRepository().setBare(false).setGitDir(new File("F:\\clone\\t4\\.git")) .setURI("https://oauth2:${access_token}@gitlab.com/xxxxxxxx/t4.git").setCredentialsProvider(provider).call();

注意:

1、jgit没有专门针对oauth2的CredentialsProvider(或者有但是我没找到...)

2、rfc6749对于resource server、authentication server有约束了从不同场景接收到携带access token的请求、响应的格式,而对于怎么处理的细节没有限定

你可能感兴趣的:(通过jgit使用oauth2 access token操作gitlab api)