-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathSSOToken.php
More file actions
64 lines (54 loc) · 1.82 KB
/
SSOToken.php
File metadata and controls
64 lines (54 loc) · 1.82 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
<?php
declare(strict_types=1);
/**
* SSO token parser and validator
*
* PHP version 8.3
*
* @category Authentication
* @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;
use Lcobucci\Clock\SystemClock;
use Lcobucci\JWT\Signer\Rsa\Sha256;
use Lcobucci\JWT\Validation\Constraint\StrictValidAt;
use Staffbase\plugins\sdk\Exceptions\SSOAuthenticationException;
use Staffbase\plugins\sdk\Exceptions\SSOException;
use Staffbase\plugins\sdk\SSOData\SharedClaimsInterface;
use Staffbase\plugins\sdk\SSOData\SSODataClaimsInterface;
use Staffbase\plugins\sdk\SSOData\SSODataTrait;
use Staffbase\plugins\sdk\Validation\HasInstanceId;
/**
* Class to parse and validate a JWT Token
*/
class SSOToken extends AbstractToken implements SharedClaimsInterface, SSODataClaimsInterface
{
use SSODataTrait;
/**
* Constructor
*
* @param string $appSecret Either a PEM key or a file:// URL.
* @param string $tokenData The token text.
* @param int|null $leeway count of seconds added to current timestamp
*
* @throws SSOAuthenticationException
* @throws SSOException on invalid parameters.
*/
public function __construct(string $appSecret, string $tokenData, ?int $leeway = 0)
{
if (empty($tokenData)) {
throw new SSOException('Parameter tokenData for SSOToken is empty.');
}
$constrains = [
new StrictValidAt(SystemClock::fromUTC(), $this->getLeewayInterval((int) $leeway)),
new HasInstanceId(),
];
$signer = new Sha256();
parent::__construct($appSecret, $tokenData, $signer, $constrains);
$this->parseToken();
$this->validateToken();
}
}