-
Notifications
You must be signed in to change notification settings - Fork 2
/
auth.php
26 lines (21 loc) · 934 Bytes
/
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
<?
include 'config.php';
$code = preg_match("/^[0-9a-f]+$/i", $_GET['code']) ? $_GET['code'] : '';
$response = @file_get_contents(TOKEN_URL . $code);
$auth_data = @json_decode($response, true);
if ($auth_data && $auth_data['access_token'] && intval($auth_data['user_id'])) {
$viewer_id = intval($auth_data['user_id']);
$expires_in = intval($auth_data['expires_in']);
$expires = time() + ($expires_in ? $expires_in : 31536000);
SetCookie('viewer_id', $viewer_id, $expires);
SetCookie('auth_key', md5(API_ID . '_' . $viewer_id . '_' . SECRET), $expires);
SetCookie('access_token', $auth_data['access_token'], $expires);
$return = substr($_GET['return'], 0, 1) == '/' ? $_GET['return'] : '/';
header('Location: ' . BASE_URL . $return);
} else {
SetCookie('viewer_id');
SetCookie('auth_key');
SetCookie('access_token');
header('Location: ' . BASE_URL . '/?error=' . urlencode($auth_data['error']));
}
?>