Skip to content

Commit b0e731a

Browse files
committed
Merge remote-tracking branch 'origin/main' into 6.x
2 parents 2a3f303 + c393f61 commit b0e731a

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

src/main/java/org/gitlab4j/api/Constants.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ public interface Constants {
5050
public enum TokenType {
5151
ACCESS,
5252
OAUTH2_ACCESS,
53+
JOB_TOKEN,
5354
PRIVATE;
5455
}
5556

src/main/java/org/gitlab4j/api/GitLabApiClient.java

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
public class GitLabApiClient implements AutoCloseable {
5858

5959
protected static final String PRIVATE_TOKEN_HEADER = "PRIVATE-TOKEN";
60+
protected static final String JOB_TOKEN_HEADER = "JOB-TOKEN";
6061
protected static final String SUDO_HEADER = "Sudo";
6162
protected static final String AUTHORIZATION_HEADER = "Authorization";
6263
protected static final String X_GITLAB_TOKEN_HEADER = "X-Gitlab-Token";
@@ -862,8 +863,8 @@ protected Invocation.Builder invocation(URL url, MultivaluedMap<String, String>
862863
}
863864
}
864865

865-
String authHeader = (tokenType == TokenType.OAUTH2_ACCESS ? AUTHORIZATION_HEADER : PRIVATE_TOKEN_HEADER);
866-
String authValue = (tokenType == TokenType.OAUTH2_ACCESS ? "Bearer " + authToken.get() : authToken.get());
866+
String authHeader = getAuthHeader();
867+
String authValue = getAuthValue();
867868
Invocation.Builder builder = target.request();
868869
if (accept == null || accept.trim().length() == 0) {
869870
builder = builder.header(authHeader, authValue);
@@ -887,6 +888,26 @@ protected Invocation.Builder invocation(URL url, MultivaluedMap<String, String>
887888
return (builder);
888889
}
889890

891+
private String getAuthValue() {
892+
switch (tokenType) {
893+
case OAUTH2_ACCESS:
894+
return "Bearer " + authToken.get();
895+
default:
896+
return authToken.get();
897+
}
898+
}
899+
900+
private String getAuthHeader() {
901+
switch (tokenType) {
902+
case OAUTH2_ACCESS:
903+
return AUTHORIZATION_HEADER;
904+
case JOB_TOKEN:
905+
return JOB_TOKEN_HEADER;
906+
default:
907+
return PRIVATE_TOKEN_HEADER;
908+
}
909+
}
910+
890911
/**
891912
* Used to set the host URL to be used by OAUTH2 login in GitLabApi.
892913
*/

0 commit comments

Comments
 (0)