Rev 22217 | Rev 23528 | Go to most recent revision | View as "text/plain" | Blame | Compare with Previous | Last modification | View Log | RSS feed
package com.spice.profitmandi.web.util;import java.io.IOException;import java.util.HashMap;import java.util.Map;import org.apache.http.conn.HttpHostConnectException;import org.springframework.http.HttpHeaders;import org.springframework.http.MediaType;import org.springframework.stereotype.Component;import com.fasterxml.jackson.core.JsonProcessingException;import com.fasterxml.jackson.databind.JsonNode;import com.fasterxml.jackson.databind.ObjectMapper;import com.spice.profitmandi.common.enumuration.SchemeType;import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;import com.spice.profitmandi.common.model.ProfitMandiConstants;import com.spice.profitmandi.common.web.client.RestClient;@Componentpublic class GoogleTokenUtil {private static final String V3_HOST_NAME = "www.googleapis.com";private static final String V3_URI = "/oauth2/v3/tokeninfo";private static final int PORT_NUMBER = 443;private final ObjectMapper objectMapper = new ObjectMapper();public String getEmailId(String token) throws ProfitMandiBusinessException{RestClient restClient = new RestClient(SchemeType.HTTPS, V3_HOST_NAME, PORT_NUMBER);Map<String, String> params = new HashMap<>();params.put(ProfitMandiConstants.ID_TOKEN, token);Map<String, String> headers = new HashMap<>(1);headers.put(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE);String responseString = null;try {responseString = restClient.get(V3_URI, params, headers);} catch (HttpHostConnectException e) {throw new ProfitMandiBusinessException("googleServerResponse", responseString, "GE_1006");}try {JsonNode rootNode = objectMapper.readTree(responseString);return rootNode.get("email").asText();}catch (JsonProcessingException jsonProcessingException) {throw new ProfitMandiBusinessException("", "", "VE_1001");}catch (IOException ioException) {throw new ProfitMandiBusinessException("", "", "VE_1001");}}}