Skip to content

Commit cb7987b

Browse files
committed
Cleaned up OAUTH2 login logic.
1 parent 4c62a27 commit cb7987b

File tree

3 files changed

+14
-6
lines changed

3 files changed

+14
-6
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
*/
2222
public abstract class AbstractApi implements Constants {
2323

24-
private final GitLabApi gitLabApi;
24+
protected final GitLabApi gitLabApi;
2525

2626
public AbstractApi(GitLabApi gitLabApi) {
2727
this.gitLabApi = gitLabApi;

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public class GitLabApi {
3333

3434
/** Specifies the version of the GitLab API to communicate with. */
3535
public enum ApiVersion {
36-
V3, V4, OAUTH2_CLIENT;
36+
V3, V4;
3737

3838
public String getApiNamespace() {
3939
return ("/api/" + name().toLowerCase());
@@ -268,7 +268,10 @@ public static GitLabApi oauth2Login(ApiVersion apiVersion, String url, String us
268268
throw new IllegalArgumentException("both username and email cannot be empty or null");
269269
}
270270

271-
GitLabApi gitLabApi = new GitLabApi(ApiVersion.OAUTH2_CLIENT, url, (String)null);
271+
// Create a GitLabApi instance set up to be used to do an OAUTH2 login.
272+
GitLabApi gitLabApi = new GitLabApi(apiVersion, url, (String)null);
273+
gitLabApi.apiClient.setHostUrlToBaseUrl();
274+
272275
if (ignoreCertificateErrors) {
273276
gitLabApi.setIgnoreCertificateErrors(true);
274277
}

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

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -210,9 +210,7 @@ public GitLabApiClient(ApiVersion apiVersion, String hostUrl, TokenType tokenTyp
210210
// Remove the trailing "/" from the hostUrl if present
211211
this.hostUrl = (hostUrl.endsWith("/") ? hostUrl.replaceAll("/$", "") : hostUrl);
212212
this.baseUrl = this.hostUrl;
213-
if (ApiVersion.OAUTH2_CLIENT != apiVersion) {
214-
this.hostUrl += apiVersion.getApiNamespace();
215-
}
213+
this.hostUrl += apiVersion.getApiNamespace();
216214

217215
this.tokenType = tokenType;
218216
this.authToken = authToken;
@@ -760,6 +758,13 @@ protected Invocation.Builder invocation(URL url, MultivaluedMap<String, String>
760758
return (builder);
761759
}
762760

761+
/**
762+
* Used to set the host URL to be used by OAUTH2 login in GitLabApi.
763+
*/
764+
void setHostUrlToBaseUrl() {
765+
this.hostUrl = this.baseUrl;
766+
}
767+
763768
/**
764769
* Returns true if the API is setup to ignore SSL certificate errors, otherwise returns false.
765770
*

0 commit comments

Comments
 (0)