<commit_before>package nz.hogwild.oauth;

import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import nz.hogwild.service.SessionStore;
import org.apache.oltu.oauth2.client.OAuthClient;
import org.apache.oltu.oauth2.client.URLConnectionClient;
import org.apache.oltu.oauth2.client.request.OAuthBearerClientRequest;
import org.apache.oltu.oauth2.client.request.OAuthClientRequest;
import org.apache.oltu.oauth2.client.response.OAuthAuthzResponse;
import org.apache.oltu.oauth2.client.response.OAuthJSONAccessTokenResponse;
import org.apache.oltu.oauth2.client.response.OAuthResourceResponse;
import org.apache.oltu.oauth2.common.OAuth;
import org.apache.oltu.oauth2.common.OAuthProviderType;
import org.apache.oltu.oauth2.common.message.types.GrantType;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

public class HogWildMicrosoftCallbackServlet extends HttpServlet {

    private String host;
    private String microsoftClientId;
    private String secret;

    public HogWildMicrosoftCallbackServlet(String host1, String microsoftClientId1, String secret1) {
        host = host1;
        microsoftClientId = microsoftClientId1;
        secret = secret1;
    }

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        HttpSession session = req.getSession(true);
        try {
            OAuthAuthzResponse oar = OAuthAuthzResponse.oauthCodeAuthzResponse(req);
            String code = oar.getCode();
            OAuthClientRequest request = OAuthClientRequest
                    .tokenProvider(OAuthProviderType.MICROSOFT)
                    .setGrantType(GrantType.AUTHORIZATION_CODE)
                    .setClientId(microsoftClientId)
                    .setClientSecret(secret)
                    .setRedirectURI("http://" + host + "/oauth2microsoft")
                    .setCode(code)
                    .buildQueryMessage();
            OAuthClient oAuthClient = new OAuthClient(new URLConnectionClient());
            OAuthJSONAccessTokenResponse oAuthResponse = oAuthClient.accessToken(request);

            String accessToken = oAuthResponse.getAccessToken();

            OAuthClientRequest bearerClientRequest = new OAuthBearerClientRequest("https://apis.live.net/v5.0/me")
                    .setAccessToken(accessToken).buildQueryMessage();
            bearerClientRequest.setHeader(OAuth.HeaderType.CONTENT_TYPE, OAuth.ContentType.JSON);

            OAuthResourceResponse resourceResponse = oAuthClient.resource(bearerClientRequest, OAuth.HttpMethod.GET, OAuthResourceResponse.class);
            JsonNode jsonNode = new ObjectMapper().reader().readTree(resourceResponse.getBody());
            JsonNode email = jsonNode.get("emails").get("account");
            SessionStore.sessionStore().addUser(session.getId(), email.textValue());
            resp.sendRedirect("/");
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
}<commit_msg>added accept header<commit_after>package nz.hogwild.oauth;

import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import nz.hogwild.service.SessionStore;
import org.apache.oltu.oauth2.client.OAuthClient;
import org.apache.oltu.oauth2.client.URLConnectionClient;
import org.apache.oltu.oauth2.client.request.OAuthBearerClientRequest;
import org.apache.oltu.oauth2.client.request.OAuthClientRequest;
import org.apache.oltu.oauth2.client.response.OAuthAuthzResponse;
import org.apache.oltu.oauth2.client.response.OAuthJSONAccessTokenResponse;
import org.apache.oltu.oauth2.client.response.OAuthResourceResponse;
import org.apache.oltu.oauth2.common.OAuth;
import org.apache.oltu.oauth2.common.OAuthProviderType;
import org.apache.oltu.oauth2.common.message.types.GrantType;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

public class HogWildMicrosoftCallbackServlet extends HttpServlet {

    private String host;
    private String microsoftClientId;
    private String secret;

    public HogWildMicrosoftCallbackServlet(String host1, String microsoftClientId1, String secret1) {
        host = host1;
        microsoftClientId = microsoftClientId1;
        secret = secret1;
    }

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        HttpSession session = req.getSession(true);
        try {
            OAuthAuthzResponse oar = OAuthAuthzResponse.oauthCodeAuthzResponse(req);
            String code = oar.getCode();
            OAuthClientRequest request = OAuthClientRequest
                    .tokenProvider(OAuthProviderType.MICROSOFT)
                    .setGrantType(GrantType.AUTHORIZATION_CODE)
                    .setClientId(microsoftClientId)
                    .setClientSecret(secret)
                    .setRedirectURI("http://" + host + "/oauth2microsoft")
                    .setCode(code)
                    .buildQueryMessage();
            OAuthClient oAuthClient = new OAuthClient(new URLConnectionClient());
            OAuthJSONAccessTokenResponse oAuthResponse = oAuthClient.accessToken(request);

            String accessToken = oAuthResponse.getAccessToken();

            OAuthClientRequest bearerClientRequest = new OAuthBearerClientRequest("https://apis.live.net/v5.0/me")
                    .setAccessToken(accessToken).buildQueryMessage();
            bearerClientRequest.setHeader(OAuth.HeaderType.CONTENT_TYPE, OAuth.ContentType.JSON);
            bearerClientRequest.setHeader("Accept", OAuth.ContentType.JSON);
            OAuthResourceResponse resourceResponse = oAuthClient.resource(bearerClientRequest, OAuth.HttpMethod.GET, OAuthResourceResponse.class);
            JsonNode jsonNode = new ObjectMapper().reader().readTree(resourceResponse.getBody());
            JsonNode email = jsonNode.get("emails").get("account");
            SessionStore.sessionStore().addUser(session.getId(), email.textValue());
            resp.sendRedirect("/");
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
}
{'fraction_non_alphanumeric': 0.09117376647257125, 'fraction_numerical': 0.0058228623965675755, 'mean_word_length': 3.4736120630568883, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 4}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5044766', 'n_tokens_mistral': 1822, 'n_tokens_neox': 1751, 'n_words': 280}