-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathClaimAccessTrait.php
More file actions
65 lines (56 loc) · 1.34 KB
/
ClaimAccessTrait.php
File metadata and controls
65 lines (56 loc) · 1.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
<?php
declare(strict_types=1);
/**
* Trait to access the claims of a JWT token.
*
* @category Token
* @copyright 2017-2025 Staffbase SE.
* @author Daniel Grosse
* @license http://www.apache.org/licenses/LICENSE-2.0
* @link https://github.com/staffbase/plugins-sdk-php
*/
namespace Staffbase\plugins\sdk\SSOData;
/**
* Trait to access the claims of a JWT token.
*/
trait ClaimAccessTrait
{
/**
* Test if a claim is set.
*
* @param string $claim name.
*
* @return boolean
*/
abstract protected function hasClaim(string $claim): bool;
/**
* Get a claim without checking for existence.
*
* @param string $claim name.
*
* @return mixed
*/
abstract protected function getClaim(string $claim);
/**
* Get an array of all available claims and their values.
*
* @return array<string, mixed>
*/
abstract protected function getAllClaims(): array;
/**
* Internal getter for all token properties.
*
* Has a check for undefined claims to make getter calls always valid.
*
* @param string $name Name of the claim.
*
* @return mixed
*/
protected function getClaimSafe(string $name)
{
if ($this->hasClaim($name)) {
return $this->getClaim($name);
}
return null;
}
}