-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathServer.php
More file actions
117 lines (96 loc) · 3.78 KB
/
Server.php
File metadata and controls
117 lines (96 loc) · 3.78 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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
<?php declare(strict_types=1);
namespace Pdsinterop\Solid\Auth\Config;
use JsonSerializable;
use Pdsinterop\Solid\Auth\Enum\OpenId\OpenIdConnectMetadata as OidcMeta;
use Pdsinterop\Solid\Auth\Exception\LogicException;
class Server implements ServerInterface
{
////////////////////////////// CLASS PROPERTIES \\\\\\\\\\\\\\\\\\\\\\\\\\\\
/** @var array */
private $data;
/** @var bool */
private $strict;
//////////////////////////// GETTERS AND SETTERS \\\\\\\\\\\\\\\\\\\\\\\\\\\
final public function get($key)
{
return $this->data[$key] ?: null;
}
private function getRecommended() : array
{
return [
OidcMeta::CLAIMS_SUPPORTED,
OidcMeta::REGISTRATION_ENDPOINT,
OidcMeta::SCOPES_SUPPORTED,
OidcMeta::USERINFO_ENDPOINT,
];
}
final public function getRequired() : array
{
$required = [
OidcMeta::AUTHORIZATION_ENDPOINT,
OidcMeta::ID_TOKEN_SIGNING_ALG_VALUES_SUPPORTED,
OidcMeta::ISSUER,
OidcMeta::JWKS_URI,
OidcMeta::RESPONSE_TYPES_SUPPORTED,
OidcMeta::SUBJECT_TYPES_SUPPORTED,
];
if ($this->strict === true) {
$required = array_merge($required, $this->getRecommended());
}
return $required;
}
//////////////////////////////// PUBLIC API \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
final public function __construct(array $data, bool $strict = false)
{
$data = array_merge([
OidcMeta::ID_TOKEN_SIGNING_ALG_VALUES_SUPPORTED => ['RS256'],
OidcMeta::SUBJECT_TYPES_SUPPORTED => ['public'],
OidcMeta::RESPONSE_TYPES_SUPPORTED => array("code","code token","code id_token","id_token code","id_token","id_token token","code id_token token","none"),
OidcMeta::TOKEN_TYPES_SUPPORTED => array("legacyPop","dpop"),
OidcMeta::RESPONSE_MODES_SUPPORTED => array("query","fragment"),
OidcMeta::GRANT_TYPES_SUPPORTED => array("authorization_code","implicit","refresh_token","client_credentials"),
OidcMeta::TOKEN_ENDPOINT_AUTH_METHODS_SUPPORTED => ["client_secret_basic"],
OidcMeta::TOKEN_ENDPOINT_AUTH_SIGNING_ALG_VALUES_SUPPORTED => ["RS256"],
OidcMeta::CODE_CHALLENGE_METHODS_SUPPORTED => ["S256"],
OidcMeta::DPOP_SIGNING_ALG_VALUES_SUPPORTED => ["RS256"],
OidcMeta::DISPLAY_VALUES_SUPPORTED => [],
OidcMeta::CLAIM_TYPES_SUPPORTED => ["normal"],
OidcMeta::CLAIMS_SUPPORTED => ["webid"],
OidcMeta::SCOPES_SUPPORTED => ["webid"],
OidcMeta::CLAIMS_PARAMETER_SUPPORTED => false,
OidcMeta::REQUEST_PARAMETER_SUPPORTED => true,
OidcMeta::REQUEST_URI_PARAMETER_SUPPORTED => false,
OidcMeta::REQUIRE_REQUEST_URI_REGISTRATION => false
], $data);
$this->data = array_filter($data, [OidcMeta::class, 'has'], ARRAY_FILTER_USE_KEY);
$this->strict = $strict;
}
final public function __toString() : string
{
return (string) json_encode($this);
}
/**
* @return array
*
* @throws LogicException for missing required properties
*/
final public function jsonSerialize() : array
{
$data = $this->data;
if ($this->validate() === false) {
$missing = $this->checkForMissing($data, $this->getRequired());
throw new LogicException('Required properties have not been set: ' . implode(', ', $missing));
}
return $data;
}
final public function validate() : bool
{
return $this->checkForMissing($this->data, $this->getRequired()) === [];
}
////////////////////////////// UTILITY METHODS \\\\\\\\\\\\\\\\\\\\\\\\\\\\\
private function checkForMissing(array $data, array $required) : array
{
$available = array_keys($data);
return array_diff($required, $available);
}
}