Subversion Repositories SmartDukaan

Rev

Rev 21728 | Rev 23505 | 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.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;

@Component
public 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);
                String responseString = restClient.get(V3_URI, params);
                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");
                }
        }
}