Source:
public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException, DataAccessException { if(username.indexOf(GithubOAuthGroupDetails.ORG_TEAM_SEPARATOR) >= 0 ) { throw new UsernameNotFoundException("Using org*team format instead of username: " + username); } User localUser = User.getById(username, false); Authentication token = SecurityContextHolder.getContext().getAuthentication(); if (token == null) { if(localUser != null && GithubSecretStorage.contains(localUser)){ String accessToken = GithubSecretStorage.retrieve(localUser); try { token = new GithubAuthenticationToken(accessToken, getGithubApiUri()); SecurityContextHolder.getContext().setAuthentication(token); } catch (IOException e) { throw new RuntimeException(e); } }else{ throw new UserMayOrMayNotExistException("Could not get auth token."); } } GithubAuthenticationToken authToken; if (token instanceof GithubAuthenticationToken) { authToken = (GithubAuthenticationToken) token; } else { throw new UserMayOrMayNotExistException("Unexpected authentication type: " + token); } if (localUser != null) { return new GithubOAuthUserDetails(username, authToken); } try { GithubOAuthUserDetails userDetails = authToken.getUserDetails(username); if (userDetails == null) throw new UsernameNotFoundException("Unknown user: " + username); GHOrganization ghOrg = authToken.loadOrganization(username); if (ghOrg != null) { throw new UsernameNotFoundException("user(" + username + ") is also an organization"); } return userDetails; } catch (IOException | Error e) { throw new DataRetrievalFailureException("loadUserByUsername (username=" + username +")", e); } }

Target:
public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException, DataAccessException { if(username.indexOf(GithubOAuthGroupDetails.ORG_TEAM_SEPARATOR) >= 0 ) { throw new UsernameNotFoundException("Using org*team format instead of username: " + username); } User localUser = User.getById(username, false); Authentication token = SecurityContextHolder.getContext().getAuthentication(); if (token == null) { if(localUser != null && GithubSecretStorage.contains(localUser)){ String accessToken = GithubSecretStorage.retrieve(localUser); try { token = new GithubAuthenticationToken(accessToken, getGithubApiUri()); } catch (IOException e) { throw new UserMayOrMayNotExistException("Could not connect to GitHub API server, target URL = " + getGithubApiUri(), e); } SecurityContextHolder.getContext().setAuthentication(token); }else{ throw new UserMayOrMayNotExistException("Could not get auth token."); } } GithubAuthenticationToken authToken; if (token instanceof GithubAuthenticationToken) { authToken = (GithubAuthenticationToken) token; } else { throw new UserMayOrMayNotExistException("Unexpected authentication type: " + token); } if (localUser != null) { return new GithubOAuthUserDetails(username, authToken); } try { GithubOAuthUserDetails userDetails = authToken.getUserDetails(username); if (userDetails == null) throw new UsernameNotFoundException("Unknown user: " + username); GHOrganization ghOrg = authToken.loadOrganization(username); if (ghOrg != null) { throw new UsernameNotFoundException("user(" + username + ") is also an organization"); } return userDetails; } catch (IOException | Error e) { throw new DataRetrievalFailureException("loadUserByUsername (username=" + username +")", e); } }