| 20180 |
aman.kumar |
1 |
package in.shop2020.serving.utils;
|
|
|
2 |
|
|
|
3 |
import java.util.HashMap;
|
|
|
4 |
import java.util.Map;
|
| 20245 |
aman.kumar |
5 |
import java.util.ResourceBundle;
|
| 20180 |
aman.kumar |
6 |
|
|
|
7 |
import org.json.JSONObject;
|
|
|
8 |
|
| 20245 |
aman.kumar |
9 |
import in.shop2020.serving.controllers.ProceedToPayController;
|
|
|
10 |
|
| 20180 |
aman.kumar |
11 |
public class FacebookUtility {
|
|
|
12 |
|
|
|
13 |
private String FBURL = "https://graph.facebook.com/debug_token";
|
|
|
14 |
private String FBGETDETAILS = "https://graph.facebook.com/me";
|
| 20245 |
aman.kumar |
15 |
private static final ResourceBundle resource = ResourceBundle.getBundle(FacebookUtility.class.getName());
|
|
|
16 |
private static final String APPID = resource.getString("facebookAppId");
|
|
|
17 |
|
|
|
18 |
//private final static String APPID = "273800242824516";
|
|
|
19 |
private final static String APPSECRET = resource.getString("facebookAppSecret");
|
| 20180 |
aman.kumar |
20 |
|
|
|
21 |
public JSONObject verifyFbToken(String accessToken, String reqEmail, boolean isFbUser, String fbId) {
|
|
|
22 |
boolean result = false;
|
|
|
23 |
Utils util = new Utils();
|
|
|
24 |
JSONObject resp = new JSONObject();
|
|
|
25 |
try {
|
|
|
26 |
|
|
|
27 |
Map<String, String> paramsMap = new HashMap<String, String>();
|
|
|
28 |
paramsMap.put("access_token", accessToken);
|
|
|
29 |
paramsMap.put("fields", "id,name,email,permissions");
|
|
|
30 |
String response = util.callRestApi(FBGETDETAILS, Utils.METHOD_GET, paramsMap, null);
|
|
|
31 |
JSONObject json = new JSONObject(response);
|
|
|
32 |
|
|
|
33 |
// check both emails
|
|
|
34 |
reqEmail = reqEmail.replace("@", "\u0040");
|
|
|
35 |
result = reqEmail.equalsIgnoreCase(json.getString("email"));
|
|
|
36 |
resp.put("id", json.getString("id"));
|
|
|
37 |
if (isFbUser) {
|
|
|
38 |
// match the facebookid with fbId
|
|
|
39 |
result = fbId.equals(json.getString("id"));
|
|
|
40 |
|
|
|
41 |
}
|
|
|
42 |
|
|
|
43 |
resp.put("status", result);
|
|
|
44 |
|
|
|
45 |
System.out.println(resp.toString());
|
|
|
46 |
} catch (Exception e) {
|
|
|
47 |
e.printStackTrace();
|
|
|
48 |
}
|
|
|
49 |
|
|
|
50 |
return resp;
|
|
|
51 |
|
|
|
52 |
}
|
|
|
53 |
|
|
|
54 |
}
|