-
Notifications
You must be signed in to change notification settings - Fork 0
/
auth.php
49 lines (46 loc) · 1.48 KB
/
auth.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
37
38
39
40
41
42
43
44
45
46
47
48
49
<?php
/* Reference implementation for proper login with Passport, I'll be taking some shortcuts for now.
require_once('router.php');
$params = explode('/', $url);
switch($params[2]){
case '':
http_response_code(301);
header('location: https://passport.yiays.com/api/oauth2/authorize?id=1&redirect='.urlencode('https://yiays.com/login/callback/'));
break;
case 'logout':
session_reset();
http_response_code(301);
header('location: /');
break;
case 'callback':
require_once('../html.secret.php'); // $secret : string
if(!isset($_GET['code'])) {
http_response_code(403);
die("Authorization failed: no auth code provided.");
}
$result = apiRequest('https://passport.yiays.com/api/oauth2/token', [
'client_id' => 1,
'client_secret' => $secret,
'code' => $_GET['code']
]);
break;
default:
http_response_code(404);
die();
}
function apiRequest($url, $post=[], $headers=array()) {
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
if($post){
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($post));
}
$headers[] = 'Accept: application/json';
if(session('access_token'))
$headers[] = 'Authorization: Bearer ' . session('access_token');
array_push($headers,"Content-Type: application/x-www-form-urlencoded");
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$response = curl_exec($ch);
return json_decode($response);
}*/
?>