Completed
Pull Request — develop (#80)
by Patrick
02:43 queued 01:03
created

oauth2callback.php (1 issue)

Severity

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
function doAuthByType($type, $src, $auth, $ref)
5
{
6
    $currentUser = false;
7
    $google = $auth->getMethodByName($type);
8
    if(!isset($_GET['code']))
9
    {
10
        $google->redirect();
11
        die();
12
    }
13 View Code Duplication
    else
14
    {
15
        $res = $google->authenticate($_GET['code'], $currentUser);
16
        switch($res)
17
        {
18
            case \Flipside\Auth\Authenticator::SUCCESS:
19
                header('Location: '.$ref);
20
                die();
21
            default:
22
            case \Flipside\Auth\Authenticator::LOGIN_FAILED:
0 ignored issues
show
case \Flipside\Auth\Auth...: login.php'); die; does not seem to be reachable.

This check looks for unreachable code. It uses sophisticated control flow analysis techniques to find statements which will never be executed.

Unreachable code is most often the result of return, die or exit statements that have been added for debug purposes.

function fx() {
    try {
        doSomething();
        return true;
    }
    catch (\Exception $e) {
        return false;
    }

    return false;
}

In the above example, the last return false will never be executed, because a return statement has already been met in every possible execution path.

Loading history...
23
                header('Location: login.php');
24
                die();
25
            case \Flipside\Auth\Authenticator::ALREADY_PRESENT:
26
                header('Location: user_exists.php?src='.$src.'&uid='.$currentUser->uid);
27
                die();
28
        }
29
    }
30
}
31
32
$auth = \Flipside\AuthProvider::getInstance();
33
$src  = false;
34
if(isset($_GET['src']))
35
{
36
    $src = $_GET['src'];
37
}
38
else if(strstr($_SERVER['HTTP_REFERER'], 'google.com') !== false)
39
{
40
    $src = 'google';
41
}
42
else if(strstr($_SERVER['HTTP_REFERER'], 'gitlab.com') !== false)
43
{
44
    $src = 'gitlab';
45
}
46
47
$ref = '.';
48
if(isset($_SERVER['HTTP_REFERER']) && strstr($_SERVER['HTTP_REFERER'], 'google.com') === false)
49
{
50
    $ref = $_SERVER['HTTP_REFERER'];
51
}
52
53
switch($src)
54
{
55
    case 'google':
56
        doAuthByType('Flipside\Auth\GoogleAuthenticator', $src, $auth, $ref);
57
        break;
58
    case 'twitter':
59
        $twitter = $auth->getMethodByName('Flipside\Auth\TwitterAuthenticator');
60
        if(!isset($_GET['oauth_token']) || !isset($_GET['oauth_verifier']))
61
        {
62
            $twitter->redirect();
63
            die();
64
        }
65 View Code Duplication
        else
66
        {
67
            $twitter->authenticate($_GET['oauth_token'], $_GET['oauth_verifier'], $current_user);
68
            switch($res)
69
            {
70
                case \Auth\Authenticator::SUCCESS:
71
                    header('Location: '.$ref);
72
                    die();
73
                default:
74
                case \Auth\Authenticator::LOGIN_FAILED:
75
                    header('Location: login.php');
76
                    die();
77
                case \Auth\Authenticator::ALREADY_PRESENT:
78
                    header('Location: user_exists.php?src=twitter&uid='.$current_user->uid);
79
                    die();
80
            }
81
        }
82
        break;
83
    case 'gitlab':
84
        doAuthByType('Flipside\Auth\OAuth2\GitLabAuthenticator', $src, $auth, $ref);
85
        break;
86
        //Generic OAuth...
87
    default:
88
        print_r($_SERVER);
89
        break;
90
}
91
/* vim: set tabstop=4 shiftwidth=4 expandtab: */
92