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

oauth2callback.php (7 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
function doAuthByType($type, $src)
0 ignored issues
show
The parameter $src is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
5
{
6
    $google = $auth->getMethodByName($type);
0 ignored issues
show
The variable $auth does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
7
    if(!isset($_GET['code']))
8
    {
9
        $google->redirect();
10
        die();
11
    }
12 View Code Duplication
    else
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...
13
    {
14
        $res = $google->authenticate($_GET['code'], $current_user);
0 ignored issues
show
The variable $current_user does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
15
        switch($res)
16
        {
17
            case \Auth\Authenticator::SUCCESS:
18
                header('Location: '.$ref);
0 ignored issues
show
The variable $ref does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

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