Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update GithubSecurityRealm.java for consistency in URL building. #118

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 14 additions & 13 deletions src/main/java/org/jenkinsci/plugins/GithubSecurityRealm.java
Original file line number Diff line number Diff line change
Expand Up @@ -357,15 +357,13 @@ public HttpResponse doCommenceLogin(StaplerRequest request, @QueryParameter Stri
for (GitHubOAuthScope s : getJenkins().getExtensionList(GitHubOAuthScope.class)) {
scopes.addAll(s.getScopesToRequest());
}
String suffix="";
String serializedScopes = oauthScopes;
// We need repo scope in order to access private repos.
// See https://developer.github.com/v3/oauth/#scopes.
if (!scopes.isEmpty()) {
suffix = "&scope="+Util.join(scopes,",")+"&state="+state;
} else {
// We need repo scope in order to access private repos
// See https://developer.github.com/v3/oauth/#scopes
suffix = "&scope=" + oauthScopes +"&state="+state;
serializedScopes = Util.join(scopes, ",");
}

String suffix = "&scope=" + serializedScopes + "&state=" + state;
return new HttpRedirect(githubWebUri + "/login/oauth/authorize?client_id="
+ clientID + suffix);
}
Expand Down Expand Up @@ -456,15 +454,15 @@ public HttpResponse doFinishLogin(StaplerRequest request)
private String getAccessToken(@Nonnull String code) throws IOException {
String content;
try (CloseableHttpClient httpClient = HttpClients.createDefault()) {
HttpPost httpost = new HttpPost(githubWebUri
+ "/login/oauth/access_token?" + "client_id=" + clientID + "&"
+ "client_secret=" + clientSecret.getPlainText() + "&" + "code=" + code);
String suffix = "&client_secret=" + clientSecret.getPlainText() + "&code=" + code;
HttpPost httpPost = new HttpPost(githubWebUri + "/login/oauth/access_token?client_id="
+ clientID + suffix);
HttpHost proxy = getProxy(httpost);
if (proxy != null) {
RequestConfig requestConfig = RequestConfig.custom().setProxy(proxy).build();
httpost.setConfig(requestConfig);
httpPost.setConfig(requestConfig);
}
org.apache.http.HttpResponse response = httpClient.execute(httpost);
org.apache.http.HttpResponse response = httpClient.execute(httpPost);
HttpEntity entity = response.getEntity();
content = EntityUtils.toString(entity);

Expand Down Expand Up @@ -499,7 +497,10 @@ private String getSecureRandomString(int n) {
*/
private HttpHost getProxy(HttpUriRequest method) throws URIException {
ProxyConfiguration proxy = getJenkins().proxy;
if (proxy==null) return null; // defensive check
if (proxy == null) {
// defensive check
return null;
}

Proxy p = proxy.createProxy(method.getURI().getHost());
switch (p.type()) {
Expand Down