BurningFlipside /
CommonCode
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; |
||
| 7 | private $oauthUrl; |
||
| 8 | |||
| 9 | public function __construct($params) |
||
| 10 | { |
||
| 11 | $this->settings = \Settings::getInstance(); |
||
|
0 ignored issues
–
show
|
|||
| 12 | $this->profilesUrl = $this->settings->getGlobalSetting('profiles_url', 'https://profiles.burningflipside.com/'); |
||
| 13 | $this->apiUrl = $this->profilesUrl.'api/v1'; |
||
| 14 | $this->oauthUrl = $this->profilesUrl.'OAUTH2'; |
||
| 15 | |||
| 16 | parent::__construct($params); |
||
| 17 | if(isset($params['api_url'])) |
||
| 18 | { |
||
| 19 | $this->apiUrl = $params['api_url']; |
||
| 20 | } |
||
| 21 | else |
||
| 22 | { |
||
| 23 | throw new \Exception('Incorrectly configured! Missing api_url parameter.'); |
||
| 24 | } |
||
| 25 | if(isset($params['oauth_url'])) |
||
| 26 | { |
||
| 27 | $this->oauthUrl = $params['oauth_url']; |
||
| 28 | } |
||
| 29 | else |
||
| 30 | { |
||
| 31 | throw new \Exception('Incorrectly configured! Missing oauth_url parameter.'); |
||
| 32 | } |
||
| 33 | } |
||
| 34 | |||
| 35 | public function getHostName() |
||
| 36 | { |
||
| 37 | return 'burningflipside.com'; |
||
| 38 | } |
||
| 39 | |||
| 40 | public function getAuthorizationUrl() |
||
| 41 | { |
||
| 42 | return $this->oauthUrl.'/authorize.php?client_id=test&redirect_uri='.urlencode($this->redirect_uri).'&scope=user'; |
||
| 43 | } |
||
| 44 | |||
| 45 | public function getAccessTokenUrl() |
||
| 46 | { |
||
| 47 | return $this->oauthUrl.'/token.php?client_id=test&redirect_uri='.urlencode($this->redirect_uri); |
||
| 48 | } |
||
| 49 | |||
| 50 | public function getUserFromToken($token) |
||
| 51 | { |
||
| 52 | if($token === false) |
||
| 53 | { |
||
| 54 | $token = \FlipSession::getVar('OAuthToken'); |
||
| 55 | } |
||
| 56 | $resp = \Httpful\Request::get($this->apiUrl.'/users/me')->addHeader('Authorization', 'token '.$token['access_token'])->send(); |
||
| 57 | $data = array('extended'=>$resp->body); |
||
| 58 | $user = new \Auth\FlipsideAPIUser($data); |
||
| 59 | $user->addLoginProvider($this->getHostName()); |
||
| 60 | return $user; |
||
| 61 | } |
||
| 62 | |||
| 63 | public function login($username, $password) |
||
| 64 | { |
||
| 65 | $resp = \Httpful\Request::post($this->apiUrl.'/login?username='.urlencode($username).'&password='.urlencode($password))->send(); |
||
| 66 | if($resp->hasErrors()) |
||
| 67 | { |
||
| 68 | return false; |
||
| 69 | } |
||
| 70 | $this->user = $resp->body->extended; |
||
| 71 | $this->user->userPassword = $password; |
||
| 72 | return array('res'=>true, 'extended'=>$this->user); |
||
| 73 | } |
||
| 74 | |||
| 75 | public function isLoggedIn($data) |
||
| 76 | { |
||
| 77 | if(isset($this->user)) |
||
| 78 | { |
||
| 79 | return true; |
||
| 80 | } |
||
| 81 | if(isset($data['res'])) |
||
| 82 | { |
||
| 83 | return $data['res']; |
||
| 84 | } |
||
| 85 | return false; |
||
| 86 | } |
||
| 87 | |||
| 88 | public function getUser($data) |
||
| 89 | { |
||
| 90 | return new \Auth\FlipsideAPIUser($data, $this->apiUrl); |
||
|
0 ignored issues
–
show
$this->apiUrl is of type string, 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...
|
|||
| 91 | } |
||
| 92 | } |
||
| 93 |
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: