Completed
Pull Request — master (#29)
by
unknown
02:49
created

Auth/OAuth2/class.LiveAuthenticator.php (1 issue)

Labels
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 LiveAuthenticator extends OAuth2Authenticator
5
{
6
    protected $app_id;
7
    protected $app_secret;
8
9
    public function __construct($params)
10
    {
11
        parent::__construct($params);
12
        $this->app_id = $params['app_id'];
13
        $this->app_secret = $params['app_secret'];
14
    }
15
16
    public function getHostName()
17
    {
18
        return 'live.com';
19
    }
20
21
    public function getAuthorizationUrl()
22
    {
23
        return 'https://login.live.com/oauth20_authorize.srf?client_id='.urlencode($this->app_id).'&redirect_uri='.urlencode($this->redirect_uri).'&response_type=code&scope=wl.basic,wl.emails';
24
    }
25
26
    public function getAccessTokenUrl()
27
    {
28
        return 'https://login.live.com/oauth20_token.srf';
29
    }
30
31
    public function doAuthPost($params)
32
    {
33
        return \Httpful\Request::post($this->getAccessTokenUrl())->sendisType(\Httpful\Mime::FORM)->addHeader('Content-Type', 'application/x-www-form-urlencoded')->body('client_id='.urlencode($this->app_id).'&client_secret='.urlencode($this->app_secret).'&redirect_uri='.urlencode($this->redirect_uri).'&code='.$params['code'].'&grant_type=authorization_code')->send();
34
    }
35
36
    public function getUserFromToken($token)
37
    {
38
        if($token === false)
39
        {
40
            $token = \FlipSession::getVar('OAuthToken');
41
        }
42
        $resp = \Httpful\Request::get('https://apis.live.net/v5.0/me')->addHeader('Authorization', 'Bearer '.$token->access_token)->send();
43
        $live_user = $resp->body;
44
        $user = new \Auth\PendingUser();
0 ignored issues
show
The call to PendingUser::__construct() misses a required argument $params.

This check looks for function calls that miss required arguments.

Loading history...
45
        $user->mail = $live_user->emails->preferred;
46
        $user->givenName = $live_user->first_name;
47
        $user->sn = $live_user->last_name;
48
        $user->addLoginProvider($this->getHostName());
49
        return $user;
50
    }
51
}
52