Commit cb7987bd authored by Greg Messner's avatar Greg Messner
Browse files

Cleaned up OAUTH2 login logic.

parent 4c62a279
......@@ -21,7 +21,7 @@ import org.gitlab4j.api.models.User;
*/
public abstract class AbstractApi implements Constants {
private final GitLabApi gitLabApi;
protected final GitLabApi gitLabApi;
public AbstractApi(GitLabApi gitLabApi) {
this.gitLabApi = gitLabApi;
......
......@@ -33,7 +33,7 @@ public class GitLabApi {
/** Specifies the version of the GitLab API to communicate with. */
public enum ApiVersion {
V3, V4, OAUTH2_CLIENT;
V3, V4;
public String getApiNamespace() {
return ("/api/" + name().toLowerCase());
......@@ -268,7 +268,10 @@ public class GitLabApi {
throw new IllegalArgumentException("both username and email cannot be empty or null");
}
GitLabApi gitLabApi = new GitLabApi(ApiVersion.OAUTH2_CLIENT, url, (String)null);
// Create a GitLabApi instance set up to be used to do an OAUTH2 login.
GitLabApi gitLabApi = new GitLabApi(apiVersion, url, (String)null);
gitLabApi.apiClient.setHostUrlToBaseUrl();
if (ignoreCertificateErrors) {
gitLabApi.setIgnoreCertificateErrors(true);
}
......
......@@ -210,9 +210,7 @@ public class GitLabApiClient {
// Remove the trailing "/" from the hostUrl if present
this.hostUrl = (hostUrl.endsWith("/") ? hostUrl.replaceAll("/$", "") : hostUrl);
this.baseUrl = this.hostUrl;
if (ApiVersion.OAUTH2_CLIENT != apiVersion) {
this.hostUrl += apiVersion.getApiNamespace();
}
this.hostUrl += apiVersion.getApiNamespace();
this.tokenType = tokenType;
this.authToken = authToken;
......@@ -760,6 +758,13 @@ public class GitLabApiClient {
return (builder);
}
/**
* Used to set the host URL to be used by OAUTH2 login in GitLabApi.
*/
void setHostUrlToBaseUrl() {
this.hostUrl = this.baseUrl;
}
/**
* Returns true if the API is setup to ignore SSL certificate errors, otherwise returns false.
*
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment