1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace cvweiss\projectbase\Controller\auth\eve; |
4
|
|
|
|
5
|
|
|
use cvweiss\projectbase\Config; |
6
|
|
|
use cvweiss\projectbase\Mongo; |
7
|
|
|
use cvweiss\projectbase\Session; |
8
|
|
|
|
9
|
|
|
class callback |
10
|
|
|
{ |
11
|
|
|
public function doGet($view, $params) |
|
|
|
|
12
|
|
|
{ |
13
|
|
|
$auth = Config::getInstance()->get("oauth2"); |
14
|
|
|
$eve = $auth['eve']; |
15
|
|
|
|
16
|
|
|
$clientID = $eve['client_id']; |
17
|
|
|
$clientSecret = $eve['client_secret']; |
18
|
|
|
|
19
|
|
|
$url = 'https://login.eveonline.com/oauth/token'; |
20
|
|
|
$verify_url = 'https://login.eveonline.com/oauth/verify'; |
21
|
|
|
$header = 'Authorization: Basic '.base64_encode($clientID . ':' . $clientSecret); |
22
|
|
|
$fields_string = ''; |
23
|
|
|
$fields = array( |
24
|
|
|
'grant_type' => 'authorization_code', |
25
|
|
|
'code' => filter_input(INPUT_GET, 'code'), |
26
|
|
|
); |
27
|
|
|
foreach ($fields as $key => $value) { |
28
|
|
|
$fields_string .= $key.'='.$value.'&'; |
29
|
|
|
} |
30
|
|
|
rtrim($fields_string, '&'); |
31
|
|
|
$ch = curl_init(); |
32
|
|
|
curl_setopt($ch, CURLOPT_URL, $url); |
33
|
|
|
curl_setopt($ch, CURLOPT_USERAGENT, Config::getInstance()->get("siteName")); |
34
|
|
|
curl_setopt($ch, CURLOPT_HTTPHEADER, array($header)); |
35
|
|
|
curl_setopt($ch, CURLOPT_POST, count($fields)); |
36
|
|
|
curl_setopt($ch, CURLOPT_POSTFIELDS, $fields_string); |
37
|
|
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); |
38
|
|
|
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true); |
39
|
|
|
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2); |
40
|
|
|
$result = curl_exec($ch); |
41
|
|
|
curl_close($ch); |
42
|
|
|
|
43
|
|
|
$json = json_decode($result, true); |
44
|
|
|
if (!isset($json['access_token'])) { |
45
|
|
|
$view->redirect('/'); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
$access_token = $json['access_token']; |
49
|
|
|
$refresh_token = $json['refresh_token']; |
50
|
|
|
$ch = curl_init(); |
51
|
|
|
// Get the Character details from SSO |
52
|
|
|
$header = 'Authorization: Bearer '.$access_token; |
53
|
|
|
curl_setopt($ch, CURLOPT_URL, $verify_url); |
54
|
|
|
curl_setopt($ch, CURLOPT_USERAGENT, Config::getInstance()->get("siteName")); |
55
|
|
|
curl_setopt($ch, CURLOPT_HTTPHEADER, array($header)); |
56
|
|
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); |
57
|
|
|
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true); |
58
|
|
|
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2); |
59
|
|
|
$result = curl_exec($ch); |
60
|
|
|
|
61
|
|
|
$json = json_decode($result, true); |
62
|
|
|
$charID = $json['CharacterID']; |
63
|
|
|
$id = "eve:sso:" . $json['CharacterID']; |
64
|
|
|
$user = Mongo::get()->findDoc("users", ['id' => $id], null, true); |
65
|
|
|
|
66
|
|
|
$user->setAll([ |
67
|
|
|
"id" => $id, |
68
|
|
|
"name" => $json['CharacterName'], |
69
|
|
|
"email" => null, |
70
|
|
|
"image" => "https://imageserver.eveonline.com/Character/${charID}_256.jpg", |
71
|
|
|
"oauth2" => "eve", |
72
|
|
|
"refresh_token" => $refresh_token |
73
|
|
|
]); |
74
|
|
|
$user->save(); |
75
|
|
|
|
76
|
|
|
Session::getSession()->set("userID", $id); |
77
|
|
|
$view->redirect('/', 302); |
78
|
|
|
} |
79
|
|
|
} |
80
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.