Completed
Pull Request — develop (#48)
by Patrick
05:51 queued 02:57
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();
0 ignored issues
show
The method sendisType() does not exist on Httpful\Request. Did you maybe mean sendsType()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
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();
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