-
Notifications
You must be signed in to change notification settings - Fork 26
Expand file tree
/
Copy pathClientEntity.php
More file actions
360 lines (315 loc) · 11.7 KB
/
ClientEntity.php
File metadata and controls
360 lines (315 loc) · 11.7 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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
<?php
declare(strict_types=1);
/*
* This file is part of the simplesamlphp-module-oidc.
*
* Copyright (C) 2018 by the Spanish Research and Academic Network.
*
* This code was developed by Universidad de Córdoba (UCO https://www.uco.es)
* for the RedIRIS SIR service (SIR: http://www.rediris.es/sir)
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace SimpleSAML\Module\oidc\Entities;
use DateTimeImmutable;
use League\OAuth2\Server\Entities\Traits\ClientTrait;
use League\OAuth2\Server\Entities\Traits\EntityTrait;
use SimpleSAML\Module\oidc\Codebooks\RegistrationTypeEnum;
use SimpleSAML\Module\oidc\Entities\Interfaces\ClientEntityInterface;
use SimpleSAML\OpenID\Codebooks\ClientRegistrationTypesEnum;
class ClientEntity implements ClientEntityInterface
{
use EntityTrait;
use ClientTrait;
public const string KEY_ID = 'id';
public const string KEY_SECRET = 'secret';
public const string KEY_NAME = 'name';
public const string KEY_DESCRIPTION = 'description';
public const string KEY_AUTH_SOURCE = 'auth_source';
public const string KEY_REDIRECT_URI = 'redirect_uri';
public const string KEY_SCOPES = 'scopes';
public const string KEY_IS_ENABLED = 'is_enabled';
public const string KEY_IS_CONFIDENTIAL = 'is_confidential';
public const string KEY_OWNER = 'owner';
public const string KEY_POST_LOGOUT_REDIRECT_URI = 'post_logout_redirect_uri';
public const string KEY_BACKCHANNEL_LOGOUT_URI = 'backchannel_logout_uri';
public const string KEY_ENTITY_IDENTIFIER = 'entity_identifier';
public const string KEY_CLIENT_REGISTRATION_TYPES = 'client_registration_types';
public const string KEY_FEDERATION_JWKS = 'federation_jwks';
public const string KEY_JWKS = 'jwks';
public const string KEY_JWKS_URI = 'jwks_uri';
public const string KEY_SIGNED_JWKS_URI = 'signed_jwks_uri';
public const string KEY_REGISTRATION_TYPE = 'registration_type';
public const string KEY_UPDATED_AT = 'updated_at';
public const string KEY_CREATED_AT = 'created_at';
public const string KEY_EXPIRES_AT = 'expires_at';
public const string KEY_IS_FEDERATED = 'is_federated';
private string $secret;
private string $description;
private ?string $authSource = null;
/**
* @var string[] $scopes
*/
private array $scopes;
private bool $isEnabled = true;
private ?string $owner = null;
/**
* @var string[]|null
*/
private ?array $postLogoutRedirectUri = null;
private ?string $backChannelLogoutUri = null;
private ?string $entityIdentifier = null;
/**
* @var string[]|null
*/
private ?array $clientRegistrationTypes = null;
/**
* @var ?array[]|null
*/
private ?array $federationJwks = null;
/**
* @var ?array[]|null
*/
private ?array $jwks = null;
private ?string $jwksUri = null;
private ?string $signedJwksUri = null;
private RegistrationTypeEnum $registrationType;
private ?DateTimeImmutable $updatedAt;
private ?DateTimeImmutable $createdAt;
private ?DateTimeImmutable $expiresAt;
private bool $isFederated;
/**
* @param string[] $redirectUri
* @param string[] $scopes
* @param string[] $postLogoutRedirectUri
* @param string[] $clientRegistrationTypes
* @param array[] $federationJwks
* @param array[] $jwks
*/
public function __construct(
string $identifier,
string $secret,
string $name,
string $description,
array $redirectUri,
array $scopes,
bool $isEnabled,
bool $isConfidential = false,
?string $authSource = null,
?string $owner = null,
array $postLogoutRedirectUri = [],
?string $backChannelLogoutUri = null,
?string $entityIdentifier = null,
?array $clientRegistrationTypes = null,
?array $federationJwks = null,
?array $jwks = null,
?string $jwksUri = null,
?string $signedJwksUri = null,
RegistrationTypeEnum $registrationType = RegistrationTypeEnum::Manual,
?DateTimeImmutable $updatedAt = null,
?DateTimeImmutable $createdAt = null,
?DateTimeImmutable $expiresAt = null,
bool $isFederated = false,
) {
$this->identifier = $identifier;
$this->secret = $secret;
$this->name = $name;
$this->description = $description;
$this->authSource = empty($authSource) ? null : $authSource;
$this->redirectUri = $redirectUri;
$this->scopes = $scopes;
$this->isEnabled = $isEnabled;
$this->isConfidential = $isConfidential;
$this->owner = empty($owner) ? null : $owner;
$this->postLogoutRedirectUri = $postLogoutRedirectUri;
$this->backChannelLogoutUri = empty($backChannelLogoutUri) ? null : $backChannelLogoutUri;
$this->entityIdentifier = empty($entityIdentifier) ? null : $entityIdentifier;
$this->clientRegistrationTypes = $clientRegistrationTypes;
$this->federationJwks = $federationJwks;
$this->jwks = $jwks;
$this->jwksUri = $jwksUri;
$this->signedJwksUri = $signedJwksUri;
$this->registrationType = $registrationType;
$this->updatedAt = $updatedAt;
$this->createdAt = $createdAt;
$this->expiresAt = $expiresAt;
$this->isFederated = $isFederated;
}
/**
* {@inheritdoc}
* @throws \JsonException
*/
public function getState(): array
{
return [
self::KEY_ID => $this->getIdentifier(),
self::KEY_SECRET => $this->getSecret(),
self::KEY_NAME => $this->getName(),
self::KEY_DESCRIPTION => $this->getDescription(),
self::KEY_AUTH_SOURCE => $this->getAuthSourceId(),
self::KEY_REDIRECT_URI => json_encode($this->getRedirectUri(), JSON_THROW_ON_ERROR),
self::KEY_SCOPES => json_encode($this->getScopes(), JSON_THROW_ON_ERROR),
self::KEY_IS_ENABLED => $this->isEnabled(),
self::KEY_IS_CONFIDENTIAL => $this->isConfidential(),
self::KEY_OWNER => $this->getOwner(),
self::KEY_POST_LOGOUT_REDIRECT_URI => json_encode($this->getPostLogoutRedirectUri(), JSON_THROW_ON_ERROR),
self::KEY_BACKCHANNEL_LOGOUT_URI => $this->getBackChannelLogoutUri(),
self::KEY_ENTITY_IDENTIFIER => $this->getEntityIdentifier(),
self::KEY_CLIENT_REGISTRATION_TYPES => is_null($this->clientRegistrationTypes) ?
null :
json_encode($this->getClientRegistrationTypes(), JSON_THROW_ON_ERROR),
self::KEY_FEDERATION_JWKS => is_null($this->federationJwks) ?
null :
json_encode($this->getFederationJwks()),
self::KEY_JWKS => is_null($this->jwks) ?
null :
json_encode($this->getJwks()),
self::KEY_JWKS_URI => $this->getJwksUri(),
self::KEY_SIGNED_JWKS_URI => $this->getSignedJwksUri(),
self::KEY_REGISTRATION_TYPE => $this->getRegistrationType()->value,
self::KEY_UPDATED_AT => $this->getUpdatedAt()?->format('Y-m-d H:i:s'),
self::KEY_CREATED_AT => $this->getCreatedAt()?->format('Y-m-d H:i:s'),
self::KEY_EXPIRES_AT => $this->getExpiresAt()?->format('Y-m-d H:i:s'),
self::KEY_IS_FEDERATED => $this->isFederated(),
];
}
public function toArray(): array
{
return [
self::KEY_ID => $this->identifier,
self::KEY_SECRET => $this->secret,
self::KEY_NAME => $this->name,
self::KEY_DESCRIPTION => $this->description,
self::KEY_AUTH_SOURCE => $this->authSource,
self::KEY_REDIRECT_URI => $this->redirectUri,
self::KEY_SCOPES => $this->scopes,
self::KEY_IS_ENABLED => $this->isEnabled,
self::KEY_IS_CONFIDENTIAL => $this->isConfidential,
self::KEY_OWNER => $this->owner,
self::KEY_POST_LOGOUT_REDIRECT_URI => $this->postLogoutRedirectUri,
self::KEY_BACKCHANNEL_LOGOUT_URI => $this->backChannelLogoutUri,
self::KEY_ENTITY_IDENTIFIER => $this->entityIdentifier,
self::KEY_CLIENT_REGISTRATION_TYPES => $this->clientRegistrationTypes,
self::KEY_FEDERATION_JWKS => $this->federationJwks,
self::KEY_JWKS => $this->jwks,
self::KEY_JWKS_URI => $this->jwksUri,
self::KEY_SIGNED_JWKS_URI => $this->signedJwksUri,
self::KEY_REGISTRATION_TYPE => $this->registrationType,
self::KEY_UPDATED_AT => $this->updatedAt,
self::KEY_CREATED_AT => $this->createdAt,
self::KEY_EXPIRES_AT => $this->expiresAt,
self::KEY_IS_FEDERATED => $this->isFederated,
];
}
public function getSecret(): string
{
return $this->secret;
}
public function restoreSecret(string $secret): ClientEntityInterface
{
$this->secret = $secret;
return $this;
}
public function getDescription(): string
{
return $this->description;
}
public function getAuthSourceId(): ?string
{
return $this->authSource;
}
public function getScopes(): array
{
return $this->scopes;
}
public function isEnabled(): bool
{
return $this->isEnabled;
}
public function getOwner(): ?string
{
return $this->owner;
}
public function getPostLogoutRedirectUri(): array
{
return $this->postLogoutRedirectUri ?? [];
}
public function setPostLogoutRedirectUri(array $postLogoutRedirectUri): void
{
$this->postLogoutRedirectUri = $postLogoutRedirectUri;
}
public function getBackChannelLogoutUri(): ?string
{
return $this->backChannelLogoutUri;
}
public function setBackChannelLogoutUri(?string $backChannelLogoutUri): void
{
$this->backChannelLogoutUri = $backChannelLogoutUri;
}
/**
* Get the RP Entity Identifier, as used in OpenID Federation specification.
* This is different from the client ID.
*/
public function getEntityIdentifier(): ?string
{
return $this->entityIdentifier;
}
public function getRedirectUris(): array
{
return is_string($this->redirectUri) ? [$this->redirectUri] : $this->redirectUri;
}
/**
* Get client registration types.
* Since this is required property, it will fall back to 'automatic', if not set on client.
*
* @return string[]
*/
public function getClientRegistrationTypes(): array
{
if (empty($this->clientRegistrationTypes)) {
return [ClientRegistrationTypesEnum::Automatic->value];
}
return $this->clientRegistrationTypes;
}
public function getFederationJwks(): ?array
{
return $this->federationJwks;
}
public function getJwks(): ?array
{
return $this->jwks;
}
public function getJwksUri(): ?string
{
return $this->jwksUri;
}
public function getSignedJwksUri(): ?string
{
return $this->signedJwksUri;
}
public function getRegistrationType(): RegistrationTypeEnum
{
return $this->registrationType;
}
public function getUpdatedAt(): ?DateTimeImmutable
{
return $this->updatedAt;
}
public function getCreatedAt(): ?DateTimeImmutable
{
return $this->createdAt;
}
public function getExpiresAt(): ?DateTimeImmutable
{
return $this->expiresAt;
}
public function isExpired(): bool
{
return $this->expiresAt !== null && $this->expiresAt < new DateTimeImmutable();
}
public function isFederated(): bool
{
return $this->isFederated;
}
}