|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* CakePHP(tm) : Rapid Development Framework (https://cakephp.org) |
|
5
|
|
|
* Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org) |
|
6
|
|
|
* |
|
7
|
|
|
* Licensed under The MIT License |
|
8
|
|
|
* For full copyright and license information, please see the LICENSE.txt |
|
9
|
|
|
* Redistributions of files must retain the above copyright notice. |
|
10
|
|
|
* |
|
11
|
|
|
* @copyright Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org) |
|
12
|
|
|
* @link https://cakephp.org CakePHP(tm) Project |
|
13
|
|
|
* @since 1.0.0 |
|
14
|
|
|
* @license https://opensource.org/licenses/mit-license.php MIT License |
|
15
|
|
|
*/ |
|
16
|
|
|
|
|
17
|
|
|
declare(strict_types=1); |
|
18
|
|
|
|
|
19
|
|
|
namespace Phauthentic\Authentication\Identifier; |
|
20
|
|
|
|
|
21
|
|
|
use ArrayAccess; |
|
22
|
|
|
use Phauthentic\Authentication\Identifier\Resolver\ResolverInterface; |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* Token Identifier |
|
26
|
|
|
*/ |
|
27
|
|
|
class TokenIdentifier extends AbstractIdentifier |
|
28
|
|
|
{ |
|
29
|
|
|
/** |
|
30
|
|
|
* Resolver |
|
31
|
|
|
* |
|
32
|
|
|
* @var \Phauthentic\Authentication\Identifier\Resolver\ResolverInterface |
|
33
|
|
|
*/ |
|
34
|
|
|
protected ResolverInterface $resolver; |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* Token Field |
|
38
|
|
|
* |
|
39
|
|
|
* @var string |
|
40
|
|
|
*/ |
|
41
|
|
|
protected string $tokenField = 'token'; |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* Data field |
|
45
|
|
|
* |
|
46
|
|
|
* @var string|null |
|
47
|
|
|
*/ |
|
48
|
|
|
protected ?string $dataField = self::CREDENTIAL_TOKEN; |
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* Constructor |
|
52
|
|
|
* |
|
53
|
48 |
|
* @param ResolverInterface $resolver Resolver instance. |
|
54
|
|
|
*/ |
|
55
|
48 |
|
public function __construct(ResolverInterface $resolver) |
|
56
|
48 |
|
{ |
|
57
|
|
|
$this->resolver = $resolver; |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
/** |
|
61
|
|
|
* Sets data field |
|
62
|
|
|
* |
|
63
|
|
|
* @param null|string $field Field name |
|
64
|
4 |
|
* @return $this |
|
65
|
|
|
*/ |
|
66
|
4 |
|
public function setDataField(?string $field): self |
|
67
|
|
|
{ |
|
68
|
4 |
|
$this->dataField = $field; |
|
69
|
|
|
|
|
70
|
|
|
return $this; |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
/** |
|
74
|
|
|
* Sets the token field |
|
75
|
|
|
* |
|
76
|
|
|
* @param string $field Field name |
|
77
|
16 |
|
* @return $this |
|
78
|
|
|
*/ |
|
79
|
16 |
|
public function setTokenField(string $field): self |
|
80
|
|
|
{ |
|
81
|
16 |
|
$this->tokenField = $field; |
|
82
|
|
|
|
|
83
|
|
|
return $this; |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
/** |
|
87
|
20 |
|
* {@inheritDoc} |
|
88
|
|
|
*/ |
|
89
|
20 |
|
public function identify(array $data): ?ArrayAccess |
|
90
|
4 |
|
{ |
|
91
|
|
|
if (!isset($data[$this->dataField])) { |
|
92
|
|
|
return null; |
|
93
|
|
|
} |
|
94
|
16 |
|
|
|
95
|
|
|
$conditions = [ |
|
96
|
|
|
$this->tokenField => $data[$this->dataField] |
|
97
|
16 |
|
]; |
|
98
|
|
|
|
|
99
|
|
|
return $this->resolver->find($conditions); |
|
100
|
|
|
} |
|
101
|
|
|
} |
|
102
|
|
|
|