forked from adlerluiz/gitpanel
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoauth.php
36 lines (29 loc) · 1.23 KB
/
oauth.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
<?php
$config = parse_ini_file('./.env');
$url = 'https://github.com/login/oauth/access_token';
$clientId = $config["CLIENT_ID"];
$clientSecret = $config["CLIENT_SECRET"];
$postsFields = new \stdClass();
$postsFields->client_id = $clientId;
$postsFields->client_secret = $clientSecret;
$postsFields->code = $_GET['code'];
$headers = array(
'Content-Type: application/json; charset=utf-8',
'Accept: application/json'
);
try {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($postsFields));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
//curl_setopt($ch, CURLOPT_NOBODY, 1);
$response = json_decode(curl_exec($ch));
$error = curl_error($ch);
curl_close($ch);
header("Location: https://".$_SERVER['HTTP_HOST']."/gitpanel/#/checkToken/" . $response->access_token);
// header("Location: http://localhost:4200/#/checkToken/" . $response->access_token);
} catch (\Exception $ex) {
return array();
}