Completed
Pull Request — develop (#48)
by Patrick
05:51 queued 02:57
created

Auth/OAuth2/class.FlipsideAuthenticator.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
namespace Auth\OAuth2;
3
4
class FlipsideAuthenticator extends OAuth2Authenticator
5
{
6
    private $apiUrl = 'https://profiles.burningflipside.com/api/v1';
7
    private $oauthUrl = 'https://profiles.burningflipside.com/OAUTH2';
8
9
    public function __construct($params)
10
    {
11
        parent::__construct($params);
12
        if(isset($params['api_url']))
13
        {
14
            $this->apiUrl = $params['api_url'];
15
        }
16
        if(isset($params['oauth_url']))
17
        {
18
            $this->oauthUrl = $params['oauth_url'];
19
        }
20
    }
21
22
    public function getHostName()
23
    {
24
        return 'burningflipside.com';
25
    }
26
27
    public function getAuthorizationUrl()
28
    {
29
        return $this->oauthUrl.'/authorize.php?client_id=test&redirect_uri='.urlencode($this->redirect_uri).'&scope=user';
30
    }
31
32
    public function getAccessTokenUrl()
33
    {
34
        return $this->oauthUrl.'/token.php?client_id=test&redirect_uri='.urlencode($this->redirect_uri);
35
    }
36
37
    public function getUserFromToken($token)
38
    {
39
        if($token === false)
40
        {
41
            $token = \FlipSession::getVar('OAuthToken');
42
        }
43
        $resp = \Httpful\Request::get($this->apiUrl.'/users/me')->addHeader('Authorization', 'token '.$token['access_token'])->send();
44
        $data = array('extended'=>$resp->body);
45
        $user = new \Auth\FlipsideAPIUser($data);
0 ignored issues
show
$data is of type array<string,array|strin..."array|string|object"}>, but the function expects a boolean.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
46
        $user->addLoginProvider($this->getHostName());
47
        return $user;
48
    }
49
50
    public function login($username, $password)
51
    {
52
        $resp = \Httpful\Request::post($this->apiUrl.'/login?username='.urlencode($username).'&password='.urlencode($password))->send();
53
        if($resp->hasErrors())
54
        {
55
            return false;
56
        }
57
        $this->user = $resp->body->extended;
58
        $this->user->userPassword = $password;
59
        return array('res'=>true, 'extended'=>$this->user);
60
    }
61
62
    public function isLoggedIn($data)
63
    {
64
        if(isset($this->user))
65
        {
66
            return true;
67
        }
68
        if(isset($data['res']))
69
        {
70
            return $data['res'];
71
        }
72
        return false;
73
    }
74
75
    public function getUser($data)
76
    {
77
        return new \Auth\FlipsideAPIUser($data, $this->apiUrl);
78
    }
79
}
80