1
|
|
|
<?php namespace nyx\auth\id\credentials; |
2
|
|
|
|
3
|
|
|
// Internal dependencies |
4
|
|
|
use nyx\auth; |
5
|
|
|
|
6
|
|
|
/** |
7
|
|
|
* Client Credentials |
8
|
|
|
* |
9
|
|
|
* A special set of Credentials useful in, for example, an oAuth context where the client application's callback URI |
10
|
|
|
* can be treated equally important in the authentication process as its ID and secret. |
11
|
|
|
* |
12
|
|
|
* @package Nyx\Auth |
13
|
|
|
* @version 0.1.0 |
14
|
|
|
* @author Michal Chojnacki <[email protected]> |
15
|
|
|
* @copyright 2012-2017 Nyx Dev Team |
16
|
|
|
* @link https://github.com/unyx/nyx |
17
|
|
|
*/ |
18
|
|
|
class Client extends auth\Credentials |
19
|
|
|
{ |
20
|
|
|
/** |
21
|
|
|
* @var string The redirect (callback) URI associated with the application. |
22
|
|
|
*/ |
23
|
|
|
protected $redirectUri; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* {@inheritDoc} |
27
|
|
|
* |
28
|
|
|
* @param string $redirectUri The redirect (callback) URI associated with the application. |
29
|
|
|
*/ |
30
|
|
|
public function __construct(string $id, $secret, string $redirectUri) |
31
|
|
|
{ |
32
|
|
|
parent::__construct($id, $secret); |
33
|
|
|
|
34
|
|
|
$this->redirectUri = $redirectUri; |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* Returns the redirect (callback) URI associated with the application. |
39
|
|
|
* |
40
|
|
|
* @return string |
41
|
|
|
*/ |
42
|
|
|
public function getRedirectUri() : string |
43
|
|
|
{ |
44
|
|
|
return $this->redirectUri; |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* {@inheritDoc} |
49
|
|
|
*/ |
50
|
|
|
public function matches(auth\interfaces\Token $that) : bool |
51
|
|
|
{ |
52
|
|
|
if (!$that instanceof static) { |
53
|
|
|
return false; |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
if ($this->redirectUri !== $that->getRedirectUri()) { |
57
|
|
|
return false; |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
return parent::matches($that); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* {@inheritDoc} |
65
|
|
|
*/ |
66
|
|
View Code Duplication |
public function unserialize($data) |
|
|
|
|
67
|
|
|
{ |
68
|
|
|
$data = unserialize($data); |
69
|
|
|
|
70
|
|
|
$this->id = $data['id']; |
71
|
|
|
$this->secret = $data['secret']; |
72
|
|
|
$this->redirectUri = $data['redirectUri']; |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* {@inheritDoc} |
77
|
|
|
*/ |
78
|
|
|
public function toArray() : array |
79
|
|
|
{ |
80
|
|
|
return [ |
81
|
|
|
'id' => $this->id, |
82
|
|
|
'secret' => $this->secret, |
83
|
|
|
'redirectUri' => $this->redirectUri |
84
|
|
|
]; |
85
|
|
|
} |
86
|
|
|
} |
87
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.