-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathoauth2callback.php
91 lines (87 loc) · 2.5 KB
/
oauth2callback.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
<?php
require('Autoload.php');
function doAuthByType($type, $src, $auth, $ref)
{
$currentUser = false;
$google = $auth->getMethodByName($type);
if(!isset($_GET['code']))
{
$google->redirect();
die();
}
else
{
$res = $google->authenticate($_GET['code'], $currentUser);
switch($res)
{
case \Flipside\Auth\Authenticator::SUCCESS:
header('Location: '.$ref);
die();
default:
case \Flipside\Auth\Authenticator::LOGIN_FAILED:
header('Location: login.php');
die();
case \Flipside\Auth\Authenticator::ALREADY_PRESENT:
header('Location: user_exists.php?src='.$src.'&uid='.$currentUser->uid);
die();
}
}
}
$auth = \Flipside\AuthProvider::getInstance();
$src = false;
if(isset($_GET['src']))
{
$src = $_GET['src'];
}
else if(strstr($_SERVER['HTTP_REFERER'], 'google.com') !== false)
{
$src = 'google';
}
else if(strstr($_SERVER['HTTP_REFERER'], 'gitlab.com') !== false)
{
$src = 'gitlab';
}
$ref = '.';
if(isset($_SERVER['HTTP_REFERER']) && strstr($_SERVER['HTTP_REFERER'], 'google.com') === false)
{
$ref = $_SERVER['HTTP_REFERER'];
}
switch($src)
{
case 'google':
doAuthByType('Flipside\Auth\GoogleAuthenticator', $src, $auth, $ref);
break;
case 'twitter':
$twitter = $auth->getMethodByName('Flipside\Auth\TwitterAuthenticator');
if(!isset($_GET['oauth_token']) || !isset($_GET['oauth_verifier']))
{
$twitter->redirect();
die();
}
else
{
$twitter->authenticate($_GET['oauth_token'], $_GET['oauth_verifier'], $current_user);
switch($res)
{
case \Auth\Authenticator::SUCCESS:
header('Location: '.$ref);
die();
default:
case \Auth\Authenticator::LOGIN_FAILED:
header('Location: login.php');
die();
case \Auth\Authenticator::ALREADY_PRESENT:
header('Location: user_exists.php?src=twitter&uid='.$current_user->uid);
die();
}
}
break;
case 'gitlab':
doAuthByType('Flipside\Auth\OAuth2\GitLabAuthenticator', $src, $auth, $ref);
break;
//Generic OAuth...
default:
print_r($_SERVER);
break;
}
/* vim: set tabstop=4 shiftwidth=4 expandtab: */