in src/main/java/org/jetbrains/teamcity/githubauth/GitHubOAuthClient.java [31:49]
public GitHubTokenResponse exchangeCodeToToken(@NotNull String code, @NotNull String clientId, @NotNull String clientSecret,
@NotNull String redirectUrl) {
HttpHeaders headers = new HttpHeaders();
headers.setAccept(singletonList(MediaType.APPLICATION_JSON));
headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED);
MultiValueMap<String, String> body = new LinkedMultiValueMap<>();
body.put("client_id", singletonList(clientId));
body.put("client_secret", singletonList(clientSecret));
body.put("code", singletonList(code));
body.put("redirect_uri", singletonList(redirectUrl));
HttpEntity<MultiValueMap<String, String>> request = new HttpEntity<>(body, headers);
try {
return restTemplate.postForObject("https://github.com/login/oauth/access_token", request, GitHubTokenResponse.class);
} catch (RestClientException e) {
throw new GitHubLoginException("Error obtaining GitHub OAuth token", e);
}
}