Source:
private String exchangeCodeForAccessToken(String code, HttpServletRequest request) { final DefaultGithubProvider[] githubProvider = new DefaultGithubProvider[1]; for (ApplicationAccountStoreMapping mapping : getApplication(request).getAccountStoreMappings()) { AccountStore accountStore = mapping.getAccountStore(); AccountStoreVisitor accountStoreVisitor = new AccountStoreVisitor() { @Override public void visit(Group group) { } @Override public void visit(Directory directory) { if ("github".equals(directory.getProvider().getProviderId())) { githubProvider[0] = (DefaultGithubProvider) directory.getProvider(); } } @Override public void visit(Organization organization) { } }; accountStore.accept(accountStoreVisitor); } Assert.notNull(githubProvider[0], "githubProvider cannot be null."); HttpClient client = HttpClientBuilder.create().build(); try { HttpPost httpPost = new HttpPost("<LINK_0>"); List<NameValuePair> nvps = new ArrayList<NameValuePair>(); nvps.add(new BasicNameValuePair("code", code)); nvps.add(new BasicNameValuePair("client_id", githubProvider[0].getClientId())); nvps.add(new BasicNameValuePair("client_secret", githubProvider[0].getClientSecret())); httpPost.setEntity(new UrlEncodedFormEntity(nvps, HTTP.UTF_8)); httpPost.addHeader("Accept", "application/json"); HttpResponse response = client.execute(httpPost); ObjectMapper objectMapper = new ObjectMapper(); @SuppressWarnings("unchecked") Map<String, String> result = objectMapper.readValue(response.getEntity().getContent(), Map.class); return result.get("access_token"); } catch (Exception e) { log.error("Couldn't exchange GitHub oAuth code for an access token", e); throw new RuntimeException(e); } }

Target:
private String exchangeCodeForAccessToken(String code, HttpServletRequest request) { final DefaultGithubProvider[] githubProvider = new DefaultGithubProvider[1]; for (ApplicationAccountStoreMapping mapping : getApplication(request).getAccountStoreMappings()) { AccountStore accountStore = mapping.getAccountStore(); AccountStoreVisitor accountStoreVisitor = new AccountStoreVisitor() { @Override public void visit(Group group) { } @Override public void visit(Directory directory) { if ("github".equals(directory.getProvider().getProviderId())) { githubProvider[0] = (DefaultGithubProvider) directory.getProvider(); } } @Override public void visit(Organization organization) { } }; accountStore.accept(accountStoreVisitor); } Assert.notNull(githubProvider[0], "githubProvider cannot be null."); HttpClient client = HttpClientBuilder.create().build(); try { HttpPost httpPost = new HttpPost(GITHUB_ACCES_TOKEN_URL); List<NameValuePair> nvps = new ArrayList<NameValuePair>(); nvps.add(new BasicNameValuePair("code", code)); nvps.add(new BasicNameValuePair("client_id", githubProvider[0].getClientId())); nvps.add(new BasicNameValuePair("client_secret", githubProvider[0].getClientSecret())); httpPost.setEntity(new UrlEncodedFormEntity(nvps, HTTP.UTF_8)); httpPost.addHeader("Accept", "application/json"); HttpResponse response = client.execute(httpPost); ObjectMapper objectMapper = new ObjectMapper(); Map<String, String> result = objectMapper.readValue(response.getEntity().getContent(), Map.class); return result.get(ACCESS_TOKEN_FIELD); } catch (Exception e) { log.error("Couldn't exchange GitHub oAuth code for an access token", e); throw new RuntimeException(e); } }