-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIdTokenLoader.php
More file actions
58 lines (47 loc) · 1.5 KB
/
IdTokenLoader.php
File metadata and controls
58 lines (47 loc) · 1.5 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
<?php
declare(strict_types=1);
/*
* The MIT License (MIT)
*
* Copyright (c) 2014-2019 Spomky-Labs
*
* This software may be modified and distributed under the terms
* of the MIT license. See the LICENSE file for details.
*/
namespace OAuth2Framework\Component\OpenIdConnect;
use function Safe\json_decode;
use Assert\Assertion;
use Jose\Component\Core\JWKSet;
use Jose\Component\Signature\JWSLoader;
class IdTokenLoader
{
private JWKSet $signatureKeySet;
private JWSLoader $jwsLoader;
public function __construct(JWSLoader $jwsLoader, JWKSet $signatureKeySet)
{
$this->signatureKeySet = $signatureKeySet;
$this->jwsLoader = $jwsLoader;
}
/**
* @return string[]
*/
public function getSupportedSignatureAlgorithms(): array
{
return $this->jwsLoader->getJwsVerifier()->getSignatureAlgorithmManager()->list();
}
public function load(IdTokenId $idTokenId): ?IdToken
{
$value = $idTokenId->getValue();
try {
$jwt = $this->jwsLoader->loadAndVerifyWithKeySet($value, $this->signatureKeySet, $signature);
Assertion::eq(0, $signature, 'Invalid ID Token.');
$payload = $jwt->getPayload();
Assertion::string($payload, 'Invalid ID Token.');
$claims = json_decode($payload, true);
Assertion::isArray($claims, 'Invalid ID Token.');
return new IdToken($idTokenId, $claims);
} catch (\Throwable $e) {
return null;
}
}
}