Subversion Repositories SmartDukaan

Rev

Rev 22111 | Rev 23505 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
21561 ashik.ali 1
package com.spice.profitmandi.web.util;
2
 
3
import java.io.IOException;
4
import java.util.HashMap;
5
import java.util.Map;
6
 
22217 ashik.ali 7
import org.springframework.http.HttpHeaders;
8
import org.springframework.http.MediaType;
21561 ashik.ali 9
import org.springframework.stereotype.Component;
10
 
11
import com.fasterxml.jackson.core.JsonProcessingException;
12
import com.fasterxml.jackson.databind.JsonNode;
13
import com.fasterxml.jackson.databind.ObjectMapper;
14
import com.spice.profitmandi.common.enumuration.SchemeType;
15
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
16
import com.spice.profitmandi.common.model.ProfitMandiConstants;
17
import com.spice.profitmandi.common.web.client.RestClient;
18
 
19
@Component
22111 ashik.ali 20
public class GoogleTokenUtil {
21561 ashik.ali 21
 
22
	private static final String V3_HOST_NAME = "www.googleapis.com";
23
	private static final String V3_URI = "/oauth2/v3/tokeninfo";
24
	private static final int PORT_NUMBER = 443;
25
	private final ObjectMapper objectMapper = new ObjectMapper();
26
 
22111 ashik.ali 27
	public String getEmailId(String token) throws ProfitMandiBusinessException{
21561 ashik.ali 28
		RestClient restClient = new RestClient(SchemeType.HTTPS, V3_HOST_NAME, PORT_NUMBER);
29
		Map<String, String> params = new HashMap<>();
30
		params.put(ProfitMandiConstants.ID_TOKEN, token);
22217 ashik.ali 31
		Map<String, String> headers = new HashMap<>(1);
32
		headers.put(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE);
33
		String responseString = restClient.get(V3_URI, params, headers);
21561 ashik.ali 34
		try {
35
			JsonNode rootNode = objectMapper.readTree(responseString);
22111 ashik.ali 36
			return rootNode.get("email").asText();
37
 
21561 ashik.ali 38
		}catch (JsonProcessingException jsonProcessingException) {
39
			throw new ProfitMandiBusinessException("", "", "VE_1001");
40
		}catch (IOException ioException) {
41
			throw new ProfitMandiBusinessException("", "", "VE_1001");
42
		}
43
	}
44
}