Fix OAuth callback URL for non-root Gerrit canonical URL
When Gerrit canonical URL is not root (e.g. myserver.com/gerrit)
we need to append the oauth suffix to it in order to be
correctly routed and managed through the reverse proxy.
Additionally the method is never called using a relative URL
and used only to initialise the config fields during object
construction.
It is better to remove the “else” branch, make the method static
and private to prevent misuse from other parts of the code.
Change-Id: I00b9be65eedd42779a0b70bb200323912ca620d7
diff --git a/github-oauth/src/main/java/com/googlesource/gerrit/plugins/github/oauth/GitHubOAuthConfig.java b/github-oauth/src/main/java/com/googlesource/gerrit/plugins/github/oauth/GitHubOAuthConfig.java
index 5a5f91f..ab04304 100644
--- a/github-oauth/src/main/java/com/googlesource/gerrit/plugins/github/oauth/GitHubOAuthConfig.java
+++ b/github-oauth/src/main/java/com/googlesource/gerrit/plugins/github/oauth/GitHubOAuthConfig.java
@@ -36,7 +36,7 @@
protected static final String CONF_SECTION = "github";
private static final String LOGIN_OAUTH_AUTHORIZE = "/login/oauth/authorize";
private static final String GITHUB_URL = "https://github.com";
- public static final String OAUTH_FINAL = "/oauth";
+ public static final String OAUTH_FINAL = "oauth";
public static final String LOGIN_OAUTH_ACCESS_TOKEN =
"/login/oauth/access_token";
public static final String OAUTH_LOGIN = "/login";
@@ -110,14 +110,9 @@
return scopes;
}
- public String getUrl(String baseUrl, String path)
+ private static String getUrl(String baseUrl, String path)
throws MalformedURLException {
- if (baseUrl.indexOf("://") > 0) {
return new URL(new URL(baseUrl), path).toExternalForm();
- } else {
- return baseUrl + (baseUrl.endsWith("/") ? "" : "/")
- + (path.startsWith("/") ? path.substring(1) : path);
- }
}
public Scope[] getDefaultScopes() {