1
|
|
|
<?php |
2
|
|
|
/* |
3
|
|
|
* This file is part of the FreshCentrifugoBundle. |
4
|
|
|
* |
5
|
|
|
* (c) Artem Henvald <[email protected]> |
6
|
|
|
* |
7
|
|
|
* For the full copyright and license information, please view the LICENSE |
8
|
|
|
* file that was distributed with this source code. |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
declare(strict_types=1); |
12
|
|
|
|
13
|
|
|
namespace Fresh\CentrifugoBundle\Token; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* JwtPayload. |
17
|
|
|
* |
18
|
|
|
* @see https://centrifugal.github.io/centrifugo/server/authentication/#claims |
19
|
|
|
* |
20
|
|
|
* @author Artem Henvald <[email protected]> |
21
|
|
|
*/ |
22
|
|
|
final class JwtPayload extends AbstractJwtPayload |
23
|
|
|
{ |
24
|
|
|
private string $subject; |
|
|
|
|
25
|
|
|
|
26
|
|
|
/** @var string[] */ |
27
|
|
|
private array $channels; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* @param string $subject |
31
|
|
|
* @param array $info |
32
|
|
|
* @param int|null $expirationTime |
33
|
|
|
* @param string|null $base64info |
34
|
|
|
* @param string[] $channels |
35
|
|
|
*/ |
36
|
|
|
public function __construct(string $subject, array $info = [], ?int $expirationTime = null, ?string $base64info = null, array $channels = []) |
37
|
|
|
{ |
38
|
|
|
$this->subject = $subject; |
39
|
|
|
$this->channels = $channels; |
40
|
|
|
|
41
|
|
|
parent::__construct($info, $expirationTime, $base64info); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* @return string |
46
|
|
|
*/ |
47
|
|
|
public function getSubject(): string |
48
|
|
|
{ |
49
|
|
|
return $this->subject; |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* @return array |
54
|
|
|
*/ |
55
|
|
|
public function getChannels(): array |
56
|
|
|
{ |
57
|
|
|
return $this->channels; |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* @return array |
62
|
|
|
*/ |
63
|
|
|
public function getPayloadData(): array |
64
|
|
|
{ |
65
|
|
|
$data = [ |
66
|
|
|
'sub' => $this->getSubject(), |
67
|
|
|
]; |
68
|
|
|
|
69
|
|
|
if (null !== $this->getExpirationTime()) { |
70
|
|
|
$data['exp'] = $this->getExpirationTime(); |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
if (!empty($this->getInfo())) { |
74
|
|
|
$data['info'] = $this->getInfo(); |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
if (null !== $this->getBase64Info()) { |
78
|
|
|
$data['b64info'] = $this->getBase64Info(); |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
if (!empty($this->getChannels())) { |
82
|
|
|
$data['channels'] = $this->getChannels(); |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
return $data; |
86
|
|
|
} |
87
|
|
|
} |
88
|
|
|
|