Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: orenhe/github-oauth-plugin
base: 074078c27e
...
head fork: orenhe/github-oauth-plugin
compare: 88f6ee7c89
Checking mergeability… Don't worry, you can still create the pull request.
  • 2 commits
  • 1 file changed
  • 0 commit comments
  • 1 contributor
Showing with 25 additions and 22 deletions.
  1. +25 −22 src/main/java/org/jenkinsci/plugins/GithubSecurityRealm.java
View
47 src/main/java/org/jenkinsci/plugins/GithubSecurityRealm.java
@@ -96,7 +96,7 @@ of this software and associated documentation files (the "Software"), to deal
private static final String DEFAULT_URI = "https://github.com";
- private String githubUri;
+ private String githubUri;
private String clientID;
private String clientSecret;
@@ -257,16 +257,16 @@ public String getClientSecret() {
public HttpResponse doCommenceLogin(StaplerRequest request, @Header("Referer") final String referer)
throws IOException {
- request.getSession().setAttribute(REFERER_ATTRIBUTE,referer);
-
- Set<String> scopes = new HashSet<String>();
- for (GitHubOAuthScope s : Jenkins.getInstance().getExtensionList(GitHubOAuthScope.class)) {
- scopes.addAll(s.getScopesToRequest());
- }
- String suffix="";
- if (!scopes.isEmpty()) {
- suffix = "&scope="+Util.join(scopes,",");
- }
+ request.getSession().setAttribute(REFERER_ATTRIBUTE,referer);
+
+ Set<String> scopes = new HashSet<String>();
+ for (GitHubOAuthScope s : Jenkins.getInstance().getExtensionList(GitHubOAuthScope.class)) {
+ scopes.addAll(s.getScopesToRequest());
+ }
+ String suffix="";
+ if (!scopes.isEmpty()) {
+ suffix = "&scope="+Util.join(scopes,",");
+ }
return new HttpRedirect(githubUri + "/login/oauth/authorize?client_id="
+ clientID + suffix);
@@ -312,20 +312,23 @@ public HttpResponse doFinishLogin(StaplerRequest request)
String githubServer = githubUri.replaceFirst("http.*\\/\\/", "");
// only set the access token if it exists.
- GithubAuthenticationToken auth = new GithubAuthenticationToken(accessToken,githubServer);
- SecurityContextHolder.getContext().setAuthentication(auth);
-
- GHUser self = auth.getGitHub().getMyself();
- User u = User.current();
- u.setFullName(self.getName());
- u.addProperty(new Mailer.UserProperty(self.getEmail()));
- }
+ GithubAuthenticationToken auth = new GithubAuthenticationToken(accessToken,githubServer);
+ SecurityContextHolder.getContext().setAuthentication(auth);
+
+ GHUser self = auth.getGitHub().getMyself();
+ User u = User.current();
+ u.setFullName(self.getName());
+ // Set email from github only if empty
+ if (u.getProperty(Mailer.UserProperty.class).getAddress() == null) {
+ u.addProperty(new Mailer.UserProperty(self.getEmail()));
+ }
+ }
else {
Log.info("github did not return an access token.");
}
- String referer = (String)request.getSession().getAttribute(REFERER_ATTRIBUTE);
- if (referer!=null) return HttpResponses.redirectTo(referer);
+ String referer = (String)request.getSession().getAttribute(REFERER_ATTRIBUTE);
+ if (referer!=null) return HttpResponses.redirectTo(referer);
return HttpResponses.redirectToContextRoot(); // referer should be always there, but be defensive
}
@@ -473,5 +476,5 @@ public GroupDetails loadGroupByGroupname(String groupName)
*/
private static final Logger LOGGER = Logger.getLogger(GithubSecurityRealm.class.getName());
- private static final String REFERER_ATTRIBUTE = GithubSecurityRealm.class.getName()+".referer";
+ private static final String REFERER_ATTRIBUTE = GithubSecurityRealm.class.getName()+".referer";
}

No commit comments for this range

Something went wrong with that request. Please try again.