Completed
Branch fix/scruitinizer (9076a5)
by Patrick
04:36 queued 01:56
created

oauth2callback.php (2 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
require('Autoload.php');
3
4
$auth = AuthProvider::getInstance();
5
$src  = false;
6
if(isset($_GET['src']))
7
{
8
    $src = $_GET['src'];
9
}
10
else if(strstr($_SERVER['HTTP_REFERER'], 'google.com') !== false)
11
{
12
    $src = 'google';
13
}
14
else if(strstr($_SERVER['HTTP_REFERER'], 'gitlab.com') !== false)
15
{
16
    $src = 'gitlab';
17
}
18
19
$ref = '.';
20
if(isset($_SERVER['HTTP_REFERER']) && strstr($_SERVER['HTTP_REFERER'], 'google.com') === false)
21
{
22
    $ref = $_SERVER['HTTP_REFERER'];
23
}
24
25
switch($src)
26
{
27 View Code Duplication
    case 'google':
0 ignored issues
show
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
28
        $google = $auth->getMethodByName('Auth\GoogleAuthenticator');
29
        if(!isset($_GET['code']))
30
        {
31
            $google->redirect();
32
            die();
33
        }
34
        else
35
        {
36
            $res = $google->authenticate($_GET['code'], $current_user);
37
            switch($res)
38
            {
39
                case \Auth\Authenticator::SUCCESS:
40
                    header('Location: '.$ref);
41
                    die();
42
                default:
43
                case \Auth\Authenticator::LOGIN_FAILED:
44
                    header('Location: login.php');
45
                    die();
46
                case \Auth\Authenticator::ALREADY_PRESENT:
47
                    header('Location: user_exists.php?src=google&uid='.$current_user->uid);
48
                    die();
49
            }
50
        }
51
        break;
52
    case 'twitter':
53
        $twitter = $auth->getMethodByName('Auth\TwitterAuthenticator');
54
        if(!isset($_GET['oauth_token']) || !isset($_GET['oauth_verifier']))
55
        {
56
            $twitter->redirect();
57
            die();
58
        }
59
        else
60
        {
61
            $twitter->authenticate($_GET['oauth_token'], $_GET['oauth_verifier'], $current_user);
62
            switch($res)
63
            {
64
                case \Auth\Authenticator::SUCCESS:
65
                    header('Location: '.$ref);
66
                    die();
67
                default:
68
                case \Auth\Authenticator::LOGIN_FAILED:
69
                    header('Location: login.php');
70
                    die();
71
                case \Auth\Authenticator::ALREADY_PRESENT:
72
                    header('Location: user_exists.php?src=twitter&uid='.$current_user->uid);
73
                    die();
74
            }
75
        }
76
        break;
77 View Code Duplication
    case 'gitlab':
0 ignored issues
show
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
78
        $gitlab = $auth->getMethodByName('Auth\OAuth2\GitLabAuthenticator');
79
        if(!isset($_GET['code']))
80
        {
81
            $google->redirect();
82
            die();
83
        }
84
        else
85
        {
86
            $res = $gitlab->authenticate($_GET['code'], $current_user);
87
            switch($res)
88
            {
89
                case \Auth\Authenticator::SUCCESS:
90
                    header('Location: '.$ref);
91
                    die();
92
                default:
93
                case \Auth\Authenticator::LOGIN_FAILED:
94
                    header('Location: login.php');
95
                    die();
96
                case \Auth\Authenticator::ALREADY_PRESENT:
97
                    header('Location: user_exists.php?src=gitlab&uid='.$current_user->uid);
98
                    die();
99
            }
100
        }
101
        //Generic OAuth...
102
    default:
103
        print_r($_SERVER);
104
        break;
105
}
106
/* vim: set tabstop=4 shiftwidth=4 expandtab: */
107