@@ -32,27 +32,33 @@ public class GitlabAPI {
3232
3333 private final String apiToken ;
3434 private final TokenType tokenType ;
35+ private AuthMethod authMethod ;
3536 private boolean ignoreCertificateErrors = false ;
3637
37- private GitlabAPI (String hostUrl , String apiToken , TokenType tokenType ) {
38+ private GitlabAPI (String hostUrl , String apiToken , TokenType tokenType , AuthMethod method ) {
3839 this .hostUrl = hostUrl .endsWith ("/" ) ? hostUrl .replaceAll ("/$" , "" ) : hostUrl ;
3940 this .apiToken = apiToken ;
4041 this .tokenType = tokenType ;
42+ this .authMethod = method ;
4143 }
4244
4345 public static GitlabSession connect (String hostUrl , String username , String password ) throws IOException {
4446 String tailUrl = GitlabSession .URL ;
45- GitlabAPI api = connect (hostUrl , null , ( TokenType ) null );
47+ GitlabAPI api = connect (hostUrl , null , null , null );
4648 return api .dispatch ().with ("login" , username ).with ("password" , password )
4749 .to (tailUrl , GitlabSession .class );
4850 }
4951
5052 public static GitlabAPI connect (String hostUrl , String apiToken ) {
51- return new GitlabAPI (hostUrl , apiToken , TokenType .PRIVATE_TOKEN );
53+ return new GitlabAPI (hostUrl , apiToken , TokenType .PRIVATE_TOKEN , AuthMethod . HEADER );
5254 }
5355
5456 public static GitlabAPI connect (String hostUrl , String apiToken , TokenType tokenType ) {
55- return new GitlabAPI (hostUrl , apiToken , tokenType );
57+ return new GitlabAPI (hostUrl , apiToken , tokenType , AuthMethod .HEADER );
58+ }
59+
60+ public static GitlabAPI connect (String hostUrl , String apiToken , TokenType tokenType , AuthMethod method ) {
61+ return new GitlabAPI (hostUrl , apiToken , tokenType , method );
5662 }
5763
5864 public GitlabAPI ignoreCertificateErrors (boolean ignoreCertificateErrors ) {
@@ -61,22 +67,18 @@ public GitlabAPI ignoreCertificateErrors(boolean ignoreCertificateErrors) {
6167 }
6268
6369 public GitlabHTTPRequestor retrieve () {
64- return new GitlabHTTPRequestor (this );
70+ return new GitlabHTTPRequestor (this ). authenticate ( apiToken , tokenType , authMethod ) ;
6571 }
6672
6773 public GitlabHTTPRequestor dispatch () {
68- return new GitlabHTTPRequestor (this ).method ("POST" );
74+ return new GitlabHTTPRequestor (this ).authenticate ( apiToken , tokenType , authMethod ). method ("POST" );
6975 }
7076
7177 public boolean isIgnoreCertificateErrors () {
7278 return ignoreCertificateErrors ;
7379 }
7480
7581 public URL getAPIUrl (String tailAPIUrl ) throws IOException {
76- if (apiToken != null ) {
77- tailAPIUrl = tailAPIUrl + (tailAPIUrl .indexOf ('?' ) > 0 ? '&' : '?' ) + tokenType .getTokenParamName () + "=" + apiToken ;
78- }
79-
8082 if (!tailAPIUrl .startsWith ("/" )) {
8183 tailAPIUrl = "/" + tailAPIUrl ;
8284 }
0 commit comments