-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinit.php
More file actions
executable file
·53 lines (46 loc) · 1.72 KB
/
init.php
File metadata and controls
executable file
·53 lines (46 loc) · 1.72 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
<?php
/**
* Created by IntelliJ IDEA.
* User: indy
* Date: 15.06.19
* Time: 23:51
*/
function goToAuthUrl() {
$url = "http://localhost:8081/auth/oauth/authorize?client_id=ClientId&redirect_uri=http://prj.local:80/callback.php&scope=user_info&response_type=code&secret=secret";
if ($_SERVER['REQUEST_METHOD'] == "GET") {
header("location: ".$url, true);
}
}
function fetchData() {
echo "asdasd";
if ($_SERVER['REQUEST_METHOD']=="GET") {
if ($_GET['code']) {
$pars = [
'client_id' => 'ClientId',
'client_secret' => 'secret',
'grant_type' => 'authorization_code',
'redirect_uri' => 'http://prj.local:80/callback.php',
'code' => $_GET['code']
];
$ctx = stream_context_create([
'http'=>array(
'method'=>"POST",
'header'=>"Accept-language: en\r\n" .
"Content-Type: application/x-www-form-urlencoded\r\n".
"Authorization: Basic ".base64_encode("ClientId:secret"),
'content' => http_build_query($pars)
)
]);
$data = @file_get_contents("http://localhost:8081/auth/oauth/token", false, $ctx);
if (!$data || $data==null) {
die('Error on try getting access token');
}
var_dump($data);
$json_data = json_decode($data);
$access_token = $json_data->access_token;
var_dump($json_data->access_token);
$user_data = @file_get_contents("http://localhost:8081/auth/user/me?access_token=".$access_token);
var_dump($user_data);
}
}
}