· 8 years ago · Nov 23, 2017, 01:40 AM
1Route::get('esitoken', function () {
2
3 $url = 'https://login.eveonline.com/oauth/token';
4 $data = array('grant_type' => 'authorization_code', 'code' => $_GET['code']);
5
6 $clientID = '';
7 $secretKey = '';
8
9
10 $options = array(
11 'http' => array(
12 'header' => "Authorization: Basic ". base64_encode($clientID .':'. $secretKey) ."\r\nContent-type: application/x-www-form-urlencoded\r\n",
13 'method' => 'POST',
14 'content' => http_build_query($data),
15 ),
16 );
17
18 $context = stream_context_create($options);
19 $result = file_get_contents($url, false, $context);
20
21 $responce = json_decode($result);
22
23 $url = 'https://login.eveonline.com/oauth/verify';
24 $data = array('grant_type' => 'authorization_code', 'code' => $_GET['code']);
25
26 $options = array(
27 'http' => array(
28 'header' => "Authorization: Bearer ". $responce->access_token ."\r\nContent-type: application/x-www-form-urlencoded\r\n",
29 'method' => 'GET',
30 'content' => http_build_query($data),
31 ),
32 );
33
34 $context = stream_context_create($options);
35 $result = file_get_contents($url, false, $context);
36 $tokeninfo = json_decode($result);
37
38die(print_r($tokeninfo));
39
40 $header = 'Authorization: Basic ' . base64_encode($clientID . ':' . $secretKey);
41 $fields_string = '';
42 $fields = array(
43 'grant_type' => 'authorization_code',
44 'code' => $_GET['code']
45 );
46
47 foreach ($fields as $key => $value) {
48 $fields_string .= $key . '=' . $value . '&';
49 }
50
51 rtrim($fields_string, '&');
52 $ch = curl_init();
53
54 curl_setopt_array(
55 $ch,
56 array(
57 CURLOPT_URL => 'https://login.eveonline.com/oauth/token',
58 CURLOPT_POST => true,
59 CURLOPT_POSTFIELDS => $fields_string,
60 CURLOPT_HTTPHEADER => array($header),
61 CURLOPT_RETURNTRANSFER => true,
62 CURLOPT_USERAGENT => 'Ch3ss/0.1b',
63 CURLOPT_SSL_VERIFYPEER => true,
64 CURLOPT_SSLVERSION => CURL_SSLVERSION_TLSv1,
65 )
66 );
67
68 $resBody = curl_exec($ch);
69 $info = curl_getinfo($ch);
70 $err = curl_errno($ch);
71 $errmsg = curl_error($ch);
72 if ($err != 0)
73 throw new Exception($errmsg, $err);
74 if (!in_array($info['http_code'], array(200, 302)))
75 throw new Exception(
76 'HTTP response not OK: ' . (int)$info['http_code'] . '. Response body: ' . $resBody,
77 $info['http_code']
78 );
79
80 curl_close($ch);
81 $response = json_decode($resBody);
82
83 print_r($tokeninfo);
84 print_r($response);
85
86});