| 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 |
|
|
|
7 |
import org.springframework.stereotype.Component;
|
|
|
8 |
|
|
|
9 |
import com.fasterxml.jackson.core.JsonProcessingException;
|
|
|
10 |
import com.fasterxml.jackson.databind.JsonNode;
|
|
|
11 |
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
12 |
import com.spice.profitmandi.common.enumuration.SchemeType;
|
|
|
13 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
|
|
14 |
import com.spice.profitmandi.common.model.ProfitMandiConstants;
|
|
|
15 |
import com.spice.profitmandi.common.web.client.RestClient;
|
|
|
16 |
|
|
|
17 |
@Component
|
| 22111 |
ashik.ali |
18 |
public class GoogleTokenUtil {
|
| 21561 |
ashik.ali |
19 |
|
|
|
20 |
private static final String V3_HOST_NAME = "www.googleapis.com";
|
|
|
21 |
private static final String V3_URI = "/oauth2/v3/tokeninfo";
|
|
|
22 |
private static final int PORT_NUMBER = 443;
|
|
|
23 |
private final ObjectMapper objectMapper = new ObjectMapper();
|
|
|
24 |
|
| 22111 |
ashik.ali |
25 |
public String getEmailId(String token) throws ProfitMandiBusinessException{
|
| 21561 |
ashik.ali |
26 |
RestClient restClient = new RestClient(SchemeType.HTTPS, V3_HOST_NAME, PORT_NUMBER);
|
|
|
27 |
Map<String, String> params = new HashMap<>();
|
|
|
28 |
params.put(ProfitMandiConstants.ID_TOKEN, token);
|
|
|
29 |
String responseString = restClient.get(V3_URI, params);
|
|
|
30 |
try {
|
|
|
31 |
JsonNode rootNode = objectMapper.readTree(responseString);
|
| 22111 |
ashik.ali |
32 |
return rootNode.get("email").asText();
|
|
|
33 |
|
| 21561 |
ashik.ali |
34 |
}catch (JsonProcessingException jsonProcessingException) {
|
|
|
35 |
throw new ProfitMandiBusinessException("", "", "VE_1001");
|
|
|
36 |
}catch (IOException ioException) {
|
|
|
37 |
throw new ProfitMandiBusinessException("", "", "VE_1001");
|
|
|
38 |
}
|
|
|
39 |
}
|
|
|
40 |
}
|