| Line 5... |
Line 5... |
| 5 |
import java.util.Map;
|
5 |
import java.util.Map;
|
| 6 |
|
6 |
|
| 7 |
import org.apache.http.conn.HttpHostConnectException;
|
7 |
import org.apache.http.conn.HttpHostConnectException;
|
| 8 |
import org.apache.logging.log4j.LogManager;
|
8 |
import org.apache.logging.log4j.LogManager;
|
| 9 |
import org.apache.logging.log4j.Logger;
|
9 |
import org.apache.logging.log4j.Logger;
|
| - |
|
10 |
import org.springframework.beans.factory.annotation.Value;
|
| 10 |
import org.springframework.http.HttpHeaders;
|
11 |
import org.springframework.http.HttpHeaders;
|
| 11 |
import org.springframework.http.MediaType;
|
12 |
import org.springframework.http.MediaType;
|
| 12 |
import org.springframework.stereotype.Component;
|
13 |
import org.springframework.stereotype.Component;
|
| 13 |
|
14 |
|
| 14 |
import com.fasterxml.jackson.core.JsonProcessingException;
|
15 |
import com.fasterxml.jackson.core.JsonProcessingException;
|
| Line 28... |
Line 29... |
| 28 |
private static final int PORT_NUMBER = 443;
|
29 |
private static final int PORT_NUMBER = 443;
|
| 29 |
private final ObjectMapper objectMapper = new ObjectMapper();
|
30 |
private final ObjectMapper objectMapper = new ObjectMapper();
|
| 30 |
|
31 |
|
| 31 |
private static final Logger LOGGER = LogManager.getLogger(GoogleTokenUtil.class);
|
32 |
private static final Logger LOGGER = LogManager.getLogger(GoogleTokenUtil.class);
|
| 32 |
|
33 |
|
| - |
|
34 |
@Value("${google.api.key}")
|
| - |
|
35 |
private String googleClientId;
|
| - |
|
36 |
|
| 33 |
public String getEmailId(String token) throws ProfitMandiBusinessException {
|
37 |
public String getEmailId(String token) throws ProfitMandiBusinessException {
|
| 34 |
RestClient restClient = new RestClient();
|
38 |
RestClient restClient = new RestClient();
|
| 35 |
Map<String, String> params = new HashMap<>();
|
39 |
Map<String, String> params = new HashMap<>();
|
| 36 |
params.put(ProfitMandiConstants.ID_TOKEN, token);
|
40 |
params.put(ProfitMandiConstants.ID_TOKEN, token);
|
| 37 |
Map<String, String> headers = new HashMap<>(1);
|
41 |
Map<String, String> headers = new HashMap<>(1);
|
| Line 44... |
Line 48... |
| 44 |
}
|
48 |
}
|
| 45 |
try {
|
49 |
try {
|
| 46 |
JsonNode rootNode = objectMapper.readTree(responseString);
|
50 |
JsonNode rootNode = objectMapper.readTree(responseString);
|
| 47 |
|
51 |
|
| 48 |
LOGGER.info("rootNode {}", rootNode);
|
52 |
LOGGER.info("rootNode {}", rootNode);
|
| - |
|
53 |
JsonNode aud = rootNode.get("aud");
|
| - |
|
54 |
JsonNode email = rootNode.get("email");
|
| - |
|
55 |
JsonNode emailVerified = rootNode.get("email_verified");
|
| - |
|
56 |
if (aud == null || !googleClientId.equals(aud.asText())) {
|
| - |
|
57 |
throw new ProfitMandiBusinessException("googleToken", aud == null ? null : aud.asText(), "Google token was not issued for this application");
|
| - |
|
58 |
}
|
| - |
|
59 |
if (email == null || emailVerified == null || !"true".equalsIgnoreCase(emailVerified.asText())) {
|
| - |
|
60 |
throw new ProfitMandiBusinessException("googleToken", email == null ? null : email.asText(), "Google account email is not verified");
|
| - |
|
61 |
}
|
| 49 |
return rootNode.get("email").asText();
|
62 |
return email.asText();
|
| 50 |
|
63 |
|
| 51 |
} catch (JsonProcessingException jsonProcessingException) {
|
64 |
} catch (JsonProcessingException jsonProcessingException) {
|
| 52 |
throw new ProfitMandiBusinessException("", "", "VE_1001");
|
65 |
throw new ProfitMandiBusinessException("", "", "VE_1001");
|
| 53 |
}
|
66 |
}
|
| 54 |
}
|
67 |
}
|