-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtoken.php
More file actions
executable file
·59 lines (46 loc) · 1.27 KB
/
token.php
File metadata and controls
executable file
·59 lines (46 loc) · 1.27 KB
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
<?php
$url = 'https://github.com/login/oauth/access_token';
/*
$data = array(
'client_id' => '9621bb7cc85da90cd062',
'client_secret' => '1e467f1c37619df19c90c3186706402cf3f10141',
'code' => urlencode($_GET['code'])
);
*/
$data = array(
'client_id' => urlencode($_GET['client_id']),
'client_secret' => urlencode($_GET['client_secret']),
'code' => urlencode($_GET['code'])
);
// use key 'http' even if you send the request to https://...
$options = array(
'http' => array(
'header' => "Content-type: application/x-www-form-urlencoded\r\n",
'method' => 'POST',
'content' => http_build_query($data),
),
);
$context = stream_context_create($options);
$result = file_get_contents($url, false, $context);
preg_match('/access_token=([0-9a-f]+)/', $result, $out);
if (sizeof($out) < 1) {
echo "Error: ";
print_r($response);
} else {
echo $out[1];
}
/*
$ch = curl_init('https://github.com/login/oauth/access_token');
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
preg_match('/access_token=([0-9a-f]+)/', $response, $out);
if (sizeof($out) < 1) {
echo "Error: ";
print_r($response);
} else {
echo $out[1];
}
curl_close($ch);
*/
?>