1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Copyright 2016 - 2018, Cake Development Corporation (http://cakedc.com) |
4
|
|
|
* |
5
|
|
|
* Licensed under The MIT License |
6
|
|
|
* Redistributions of files must retain the above copyright notice. |
7
|
|
|
* |
8
|
|
|
* @copyright Copyright 2016 - 2018, Cake Development Corporation (http://cakedc.com) |
9
|
|
|
* @license MIT License (http://www.opensource.org/licenses/mit-license.php) |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org) |
14
|
|
|
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org) |
15
|
|
|
* |
16
|
|
|
* Licensed under The MIT License |
17
|
|
|
* For full copyright and license information, please see the LICENSE.txt |
18
|
|
|
* Redistributions of files must retain the above copyright notice. |
19
|
|
|
* |
20
|
|
|
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org) |
21
|
|
|
* @link http://cakephp.org CakePHP(tm) Project |
22
|
|
|
* @since 0.10.0 |
23
|
|
|
* @license http://www.opensource.org/licenses/mit-license.php MIT License |
24
|
|
|
*/ |
25
|
|
|
|
26
|
|
|
namespace CakeDC\Api\Service\Auth\Authenticate; |
27
|
|
|
|
28
|
|
|
use Authentication\IdentityInterface; |
29
|
|
|
use Cake\Datasource\EntityInterface; |
30
|
|
|
use Cake\Http\Response; |
31
|
|
|
use Cake\Http\ServerRequest; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* Class FormAuthenticate. |
35
|
|
|
*/ |
36
|
|
|
class Psr7Authenticate extends BaseAuthenticate |
37
|
|
|
{ |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* Authenticates the identity contained in a request. Will use the `config.userModel`, and `config.fields` |
41
|
|
|
* to find POST data that is used to find a matching record in the `config.userModel`. Will return false if |
42
|
|
|
* there is no post data, either username or password is missing, or if the scope conditions have not been met. |
43
|
|
|
* |
44
|
|
|
* @param \Cake\Http\ServerRequest $request The request that contains login information. |
45
|
|
|
* @param \Cake\Http\Response $response Unused response object. |
46
|
|
|
* @return mixed False on login failure. An array of User data on success. |
47
|
|
|
*/ |
48
|
|
|
public function authenticate(ServerRequest $request, Response $response) |
49
|
|
|
{ |
50
|
|
|
return $this->getUser($request); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* Get a user based on information in the request. Primarily used by stateless authentication |
55
|
|
|
* systems like basic and digest auth. |
56
|
|
|
* |
57
|
|
|
* @param \Cake\Http\ServerRequest $request Request object. |
58
|
|
|
* @return mixed Either false or an array of user information |
59
|
|
|
*/ |
60
|
|
|
public function getUser(ServerRequest $request) |
61
|
|
|
{ |
62
|
|
|
$authResult = $request->getAttribute('authentication')->getResult(); |
63
|
|
|
if (!$authResult->isValid()) { |
64
|
|
|
return false; |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
$result = $request->getAttribute('identity'); |
68
|
|
|
|
69
|
|
|
if ($result instanceof IdentityInterface) { |
|
|
|
|
70
|
|
|
$result = $result->getOriginalData(); |
71
|
|
|
} |
72
|
|
|
if ($result instanceof EntityInterface) { |
73
|
|
|
return $result->toArray(); |
|
|
|
|
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
return $result; |
77
|
|
|
} |
78
|
|
|
} |
79
|
|
|
|
This error could be the result of:
1. Missing dependencies
PHP Analyzer uses your
composer.json
file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects thecomposer.json
to be in the root folder of your repository.Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the
require
orrequire-dev
section?2. Missing use statement
PHP does not complain about undefined classes in
ìnstanceof
checks. For example, the following PHP code will work perfectly fine:If you have not tested against this specific condition, such errors might go unnoticed.