Issues (150)

src/interfaces/models/Oauth2ClientInterface.php (4 issues)

1
<?php
2
3
namespace rhertogh\Yii2Oauth2Server\interfaces\models;
4
5
use League\OAuth2\Server\Entities\ClientEntityInterface;
6
use League\OAuth2\Server\Repositories\ScopeRepositoryInterface;
7
use rhertogh\Yii2Oauth2Server\interfaces\components\encryption\Oauth2CryptographerInterface;
8
use rhertogh\Yii2Oauth2Server\interfaces\models\base\Oauth2ActiveRecordInterface;
9
use rhertogh\Yii2Oauth2Server\interfaces\models\base\Oauth2EnabledInterface;
10
use rhertogh\Yii2Oauth2Server\interfaces\models\base\Oauth2EncryptedStorageInterface;
11
use rhertogh\Yii2Oauth2Server\interfaces\models\base\Oauth2IdentifierInterface;
12
use rhertogh\Yii2Oauth2Server\interfaces\models\queries\Oauth2ClientQueryInterface;
13
use rhertogh\Yii2Oauth2Server\interfaces\models\queries\Oauth2ClientScopeQueryInterface;
14
use rhertogh\Yii2Oauth2Server\Oauth2Module;
15
16
interface Oauth2ClientInterface extends
17
    Oauth2ActiveRecordInterface,
18
    Oauth2IdentifierInterface,
19
    Oauth2EnabledInterface,
20
    Oauth2EncryptedStorageInterface,
21
    ClientEntityInterface
22
{
23
    /**
24
     * Client Type "Confidential": Identifies the client via a shared secret.
25
     * Note: This should only be trusted in case the client can store the secret securely, e.g. another server.
26
     * @since 1.0.0
27
     * @see https://oauth.net/2/client-types/
28
     */
29
    public const TYPE_CONFIDENTIAL = 1;
30
    /**
31
     * Client Type "Public": In case the client can not store a secret securely it should be declared public,
32
     * e.g. web- or mobile applications.
33
     * @since 1.0.0
34
     * @see https://oauth.net/2/client-types/
35
     */
36
    public const TYPE_PUBLIC = 2;
37
    /**
38
     * Client Types
39
     * @since 1.0.0
40
     * @see https://oauth.net/2/client-types/
41
     */
42
    public const TYPES = [
43
        self::TYPE_CONFIDENTIAL,
44
        self::TYPE_PUBLIC,
45
    ];
46
47
    public const OIDC_RP_INITIATED_LOGOUT_DISABLED = 0;
48
    public const OIDC_RP_INITIATED_LOGOUT_ENABLED = 1;
49
    public const OIDC_RP_INITIATED_LOGOUT_ENABLED_WITHOUT_CONFIRMATION = 2;
50
51
    public const OIDC_RP_INITIATED_LOGOUT_OPTIONS = [
52
        self::OIDC_RP_INITIATED_LOGOUT_DISABLED,
53
        self::OIDC_RP_INITIATED_LOGOUT_ENABLED,
54
        self::OIDC_RP_INITIATED_LOGOUT_ENABLED_WITHOUT_CONFIRMATION,
55
    ];
56
57
    /**
58
     * @inheritDoc
59
     * @return Oauth2ClientQueryInterface
60
     */
61
    public static function find();
62
63
    /**
64
     * Get the Oauth2Module
65
     * @return Oauth2Module
66
     * @since 1.0.0
67
     */
68
    public function getModule();
69
70
    /**
71
     * Set the Oauth2Module
72
     * @param Oauth2Module $module
73
     * @return $this
74
     * @since 1.0.0
75
     */
76
    public function setModule($module);
77
78
    /**
79
     * Set the client name
80
     * @param string $name
81
     * @return $this
82
     * @since 1.0.0
83
     */
84
    public function setName($name);
85
86
    /**
87
     * Get the client type
88
     * @return int
89
     * @since 1.0.0
90
     * @see self::TYPES
91
     */
92
    public function getType();
93
94
    /**
95
     * Set the client type
96
     * @param int $type
97
     * @return $this
98
     * @since 1.0.0
99
     * @see self::TYPES
100
     */
101
    public function setType($type);
102
103
    /**
104
     * Get the client logo URI
105
     * @return string $logoUri
106
     * @since 1.0.0
107
     */
108
    public function getLogoUri();
109
110
    /**
111
     * Set the client logo URI
112
     * @param string $logoUri
113
     * @return $this
114
     * @since 1.0.0
115
     */
116
    public function setLogoUri($logoUri);
117
118
    /**
119
     * Get the client Terms of Service URI
120
     * @return string $tosUri
121
     * @since 1.0.0
122
     */
123
    public function getTermsOfServiceUri();
124
125
    /**
126
     * Set the client Terms of Service URI
127
     * @param string $tosUri
128
     * @return $this
129
     * @since 1.0.0
130
     */
131
    public function setTermsOfServiceUri($tosUri);
132
133
    /**
134
     * Get the client contacts information
135
     * @return string $contacts
136
     * @since 1.0.0
137
     */
138
    public function getContacts();
139
140
    /**
141
     * Set the client contacts information
142
     * @param string $contacts
143
     * @return $this
144
     * @since 1.0.0
145
     */
146
    public function setContacts($contacts);
147
148
    /**
149
     * @inheritdoc
150
     * @return string[]
151
     */
152
    public function getRedirectUri();
153
154
    /**
155
     * Sets the one or multiple redirect URIs
156
     * @param string|string[]|null $uri
157
     * @return $this
158
     * @since 1.0.0
159
     */
160
    public function setRedirectUri($uri);
161
162
    /**
163
     * Get the post logout redirect URI(s)
164
     * @return string[]|null
165
     * @since 1.0.0
166
     */
167
    public function getPostLogoutRedirectUris();
168
169
    /**
170
     * Sets the one or multiple post logout redirect URI(s)
171
     * @param string|string[]|null $postLogoutRedirectUris
172
     * @return $this
173
     * @since 1.0.0
174
     */
175
    public function setPostLogoutRedirectUris($postLogoutRedirectUris);
176
177
    /**
178
     * Get configuration for parsing environment variables in the redirect URI(s) and/or
179
     * secrets (`secret` and `oldSecret`).
180
     *
181
     * @return array{
0 ignored issues
show
Documentation Bug introduced by
The doc comment array{ at position 2 could not be parsed: the token is null at position 2.
Loading history...
182
     *             redirectUris?: array{
183
     *                 allowList: string[],
184
     *                 denyList?: string[]|null,
185
     *                 parseNested?: bool,
186
     *                 exceptionWhenNotSet?: bool,
187
     *                 exceptionWhenNotAllowed?: bool,
188
     *             },
189
     *             secrets?: array{
190
     *                 allowList: string[],
191
     *                 denyList?: string[]|null,
192
     *                 parseNested?: bool,
193
     *                 exceptionWhenNotSet?: bool,
194
     *                 exceptionWhenNotAllowed?: bool,
195
     *             },
196
     *         }|null
197
     * @since 1.0.0
198
     * @see \rhertogh\Yii2Oauth2Server\helpers\EnvironmentHelper::parseEnvVars()
199
     */
200
    public function getEnvVarConfig();
201
202
    /**
203
     * When configured, environment variables specified in the redirect URI(s) and/or
204
     * secrets (`secret` and `oldSecret`) will be replaced by their values.
205
     *
206
     * @param array{
207
     *            redirectUris?: array{
208
     *                allowList: string[],
209
     *                denyList?: string[]|null,
210
     *                parseNested?: bool,
211
     *                exceptionWhenNotSet?: bool,
212
     *                exceptionWhenNotAllowed?: bool,
213
     *            },
214
     *            secrets?: array{
215
     *                allowList: string[],
216
     *                denyList?: string[]|null,
217
     *                parseNested?: bool,
218
     *                exceptionWhenNotSet?: bool,
219
     *                exceptionWhenNotAllowed?: bool,
220
     *            },
221
     *        }|null $config
222
     * @return $this
223
     * @since 1.0.0
224
     * @see \rhertogh\Yii2Oauth2Server\helpers\EnvironmentHelper::parseEnvVars()
225
     */
226
    public function setEnvVarConfig($config);
227
228
    /**
229
     * Get configuration for parsing environment variables in the redirect URI(s).
230
     * Falls back to the Oauth2Module::$clientRedirectUrisEnvVarConfig if there is no specific configuration for this
231
     * client.
232
     * Please see `EnvironmentHelper::parseEnvVars()` for more details.
233
     *
234
     * @return array{
0 ignored issues
show
Documentation Bug introduced by
The doc comment array{ at position 2 could not be parsed: the token is null at position 2.
Loading history...
235
     *             allowList: string[],
236
     *             denyList?: string[]|null,
237
     *             parseNested?: bool,
238
     *             exceptionWhenNotSet?: bool,
239
     *             exceptionWhenNotAllowed?: bool,
240
     *         }|null
241
     * @since 1.0.0
242
     * @see \rhertogh\Yii2Oauth2Server\helpers\EnvironmentHelper::parseEnvVars()
243
     */
244
    public function getRedirectUrisEnvVarConfig();
245
246
    /**
247
     * Get configuration for parsing environment variables in the secrets (`secret` and `oldSecret`).
248
     * Please see `EnvironmentHelper::parseEnvVars()` for more details.
249
     *
250
     * @return array{
0 ignored issues
show
Documentation Bug introduced by
The doc comment array{ at position 2 could not be parsed: the token is null at position 2.
Loading history...
251
     *             allowList: string[],
252
     *             denyList?: string[]|null,
253
     *             parseNested?: bool,
254
     *             exceptionWhenNotSet?: bool,
255
     *             exceptionWhenNotAllowed?: bool,
256
     *         }|null
257
     * @since 1.0.0
258
     * @see \rhertogh\Yii2Oauth2Server\helpers\EnvironmentHelper::parseEnvVars()
259
     */
260
    public function getSecretsEnvVarConfig();
261
262
    /**
263
     * Validate the client against the full redirect URI, or allow for a variable "query" part.
264
     * @return bool
265
     * @see setAllowVariableRedirectUriQuery
266
     * @since 1.0.0
267
     */
268
    public function isVariableRedirectUriQueryAllowed();
269
270
    /**
271
     * By default, the client is validated against the full redirect URI including the "query" part.
272
     * If the "query" part of the return uri is variable it may be marked as such.
273
     *
274
     * Warning: Using a variable return uri query should be avoided, since it might introduce an attack vector.
275
     *          You probably should store and use the "state" on the client side.
276
     * @param bool $allowVariableRedirectUriQuery
277
     * @return $this
278
     * @since 1.0.0
279
     */
280
    public function setAllowVariableRedirectUriQuery($allowVariableRedirectUriQuery);
281
282
    /**
283
     * Is the client is allowed to use "generic" scopes. By default, scopes must be explicitly linked to the client.
284
     * @return bool
285
     * @since 1.0.0
286
     */
287
    public function getAllowGenericScopes();
288
289
    /**
290
     * Set if the client is allowed to use "generic" scopes. By default, scopes must be explicitly linked to the client.
291
     * @param bool $allowGenericScopes
292
     * @return $this
293
     * @since 1.0.0
294
     */
295
    public function setAllowGenericScopes($allowGenericScopes);
296
297
    /**
298
     * Will the server throw an exception when an unknown scope is requested by the client.
299
     * Note: If this setting is not explicitly defined for the client, the Oauth2Module's value will be used.
300
     * @return bool|null
301
     * @since 1.0.0
302
     */
303
    public function getExceptionOnInvalidScope();
304
305
    /**
306
     * Set if server throws an exception when an unknown scope is requested by the client.
307
     * @param bool|null $exceptionOnInvalidScope
308
     * @return $this
309
     * @since 1.0.0
310
     */
311
    public function setExceptionOnInvalidScope($exceptionOnInvalidScope);
312
313
    /**
314
     * Get the Grant Types enabled for the client.
315
     * @return integer
316
     * @since 1.0.0
317
     */
318
    public function getGrantTypes();
319
320
    /**
321
     * Set the Grant Types enabled for the client.
322
     *
323
     * @param int $grantTypes
324
     * @return $this
325
     * @since 1.0.0
326
     */
327
    public function setGrantTypes($grantTypes);
328
329
    /**
330
     * Validates if a Grant Type is enabled for the client.
331
     * @return bool
332
     * @since 1.0.0
333
     */
334
    public function validateGrantType($grantTypeIdentifier);
335
336
    /**
337
     * Set the client secret. It will be encrypted by the cryptographer.
338
     * Note: For security if $oldSecretValidUntil is not specified the old secret will be cleared
339
     * (regardless if it was expired or not).
340
     *
341
     * @param string|null $secret
342
     * @param Oauth2CryptographerInterface $cryptographer
343
     * @param \DateTimeImmutable|\DateInterval|null $oldSecretValidUntil
344
     * @param string|null $keyName The name of the key to use for the encryption
345
     * (must be present in the available keys).
346
     * @return $this
347
     * @since 1.0.0
348
     */
349
    public function setSecret($secret, $cryptographer, $oldSecretValidUntil = null, $keyName = null);
350
351
    /**
352
     * Set the client secret (and optionally the old_secret) to environment variable names.
353
     *
354
     * @param string $secretEnvVarName
355
     * @param string|null $oldSecretEnvVarName
356
     * @param \DateTimeImmutable|\DateInterval|null $oldSecretValidUntil
357
     * @return $this
358
     * @since 1.0.0
359
     */
360
    public function setSecretsAsEnvVars($secretEnvVarName, $oldSecretEnvVarName = null, $oldSecretValidUntil = null);
361
362
    /**
363
     * Validate new secret against the validation rules.
364
     * @param string $secret
365
     * @param string|null $error Will contain the error message in case the secret is invalid.
366
     * @return bool
367
     * @since 1.0.0
368
     * @see getMinimumSecretLength
369
     */
370
    public function validateNewSecret($secret, &$error);
371
372
    /**
373
     * Get the minimum length for new client secrets.
374
     * @return integer
375
     * @since 1.0.0
376
     */
377
    public function getMinimumSecretLength();
378
379
    /**
380
     * Set the minimum length for new client secrets.
381
     *
382
     * @param int $minimumSecretLength
383
     * @return $this
384
     * @since 1.0.0
385
     */
386
    public function setMinimumSecretLength($minimumSecretLength);
387
388
    /**
389
     * Get the decrypted secret.
390
     * @param Oauth2CryptographerInterface $cryptographer
391
     * @return string
392
     * @since 1.0.0
393
     */
394
    public function getDecryptedSecret($cryptographer);
395
396
    /**
397
     * Get the decrypted old secret.
398
     * @param Oauth2CryptographerInterface $cryptographer
399
     * @return string
400
     * @since 1.0.0
401
     */
402
    public function getDecryptedOldSecret($cryptographer);
403
404
    /**
405
     * Get the old secret expiry date/time.
406
     * @return \DateTimeImmutable
407
     * @since 1.0.0
408
     */
409
    public function getOldSecretValidUntil();
410
411
    /**
412
     * Validate a secret against the stored one.
413
     * If an "old" secret is set (and its "valid until" date is valid) the secret will also be validated against it
414
     * in case the regular stored secret fails.
415
     * @param string $secret
416
     * @param Oauth2CryptographerInterface $cryptographer
417
     * @return bool
418
     * @since 1.0.0
419
     */
420
    public function validateSecret($secret, $cryptographer);
421
422
    /**
423
     * Validate the requested scopes for the client.
424
     * @param string[] $scopeIdentifiers
425
     * @return bool
426
     * @see getAllowedScopes()
427
     * @since 1.0.0
428
     */
429
    public function validateAuthRequestScopes($scopeIdentifiers, &$unknownScopes = [], &$unauthorizedScopes = []);
430
431
    /**
432
     * Get the requested scopes that are allowed for this client.
433
     * When $requestedScopeIdentifiers is `true`, all possible scopes are returned.
434
     * @param string[]|true $requestedScopeIdentifiers
435
     * @return Oauth2ScopeInterface[]
436
     * @since 1.0.0
437
     */
438
    public function getAllowedScopes($requestedScopeIdentifiers = []);
439
440
    /**
441
     * Get the ClientScopes for this client.
442
     * @return Oauth2ClientScopeQueryInterface
443
     * @since 1.0.0
444
     */
445
    public function getClientScopes();
446
447
    /**
448
     * Get user account selection configuration for this client.
449
     * @return int|null
450
     * @since 1.0.0
451
     * @see Oauth2Module::USER_ACCOUNT_SELECTION_ALWAYS
452
     */
453
    public function getUserAccountSelection();
454
455
    /**
456
     * Set user account selection configuration for this client.
457
     * @param int|null $userAccountSelectionConfig
458
     * @since 1.0.0
459
     * @return $this
460
     * @see Oauth2Module::USER_ACCOUNT_SELECTION_ALWAYS
461
     */
462
    public function setUserAccountSelection($userAccountSelectionConfig);
463
464
    /**
465
     * Are end-user allowed to authorize this client.
466
     * @return bool
467
     * @since 1.0.0
468
     */
469
    public function endUsersMayAuthorizeClient();
470
471
    /**
472
     * Set if end-users are allowed to authorize this client.
473
     * @param bool $endUsersMayAuthorizeClient
474
     * @since 1.0.0
475
     * @return $this
476
     */
477
    public function setEndUsersMayAuthorizeClient($endUsersMayAuthorizeClient);
478
479
    /**
480
     * Are authorization code requests without PKCE allowed.
481
     * @return bool
482
     * @since 1.0.0
483
     */
484
    public function isAuthCodeWithoutPkceAllowed();
485
486
    /**
487
     * Set if authorization code requests without PKCE are allowed.
488
     * @param bool $allowAuthCodeWithoutPkce
489
     * @return $this
490
     * @since 1.0.0
491
     */
492
    public function setAllowAuthCodeWithoutPkce($allowAuthCodeWithoutPkce);
493
494
    /**
495
     * Should client authorization by the user be skipped if all scopes are allowed.
496
     * @return bool
497
     * @since 1.0.0
498
     */
499
    public function skipAuthorizationIfScopeIsAllowed();
500
501
    /**
502
     * Set if client authorization by the user should be skipped if all scopes are allowed.
503
     * @param bool $skipAuthIfScopeIsAllowed
504
     * @return $this
505
     * @since 1.0.0
506
     */
507
    public function setSkipAuthorizationIfScopeIsAllowed($skipAuthIfScopeIsAllowed);
508
509
    /**
510
     * Get the user id for clients that use the 'client credentials' Grant Type.
511
     * @return int|string|null
512
     * @since 1.0.0
513
     */
514
    public function getClientCredentialsGrantUserId();
515
516
    /**
517
     * Set the user id for clients that use the 'client credentials' Grant Type.
518
     * @param int|string|null $userId
519
     * @return $this
520
     * @since 1.0.0
521
     */
522
    public function setClientCredentialsGrantUserId($userId);
523
524
    /**
525
     * Warning! Enabling this setting might introduce privacy concerns since the client could poll for the online status
526
     * of a user.
527
     *
528
     * @return bool If this setting is disabled in case of OpenID Connect Context the Access Token won't include a
529
     * Refresh Token when the 'offline_access' scope is not included in the authorization request.
530
     * In some cases it might be needed to always include a Refresh Token, in that case enable this setting and
531
     * implement the `Oauth2OidcUserSessionStatusInterface` on the User Identity model.
532
     * @since 1.0.0
533
     */
534
    public function getOpenIdConnectAllowOfflineAccessWithoutConsent();
535
536
    /**
537
     * Warning! Enabling this setting might introduce privacy concerns since the client could poll for the online status
538
     * of a user.
539
     *
540
     * @param bool $allowOfflineAccessWithoutConsent If this setting is disabled in case of OpenID Connect Context the
541
     * Access Token won't include a Refresh Token when the 'offline_access' scope is not included in the authorization
542
     * request.
543
     * In some cases it might be needed to always include a Refresh Token, in that case enable this setting and
544
     * implement the `Oauth2OidcUserSessionStatusInterface` on the User Identity model.
545
     * @return $this
546
     * @since 1.0.0
547
     */
548
    public function setOpenIdConnectAllowOfflineAccessWithoutConsent($allowOfflineAccessWithoutConsent);
549
550
    /**
551
     * @return int Get RP Initiated Logout configuration.
552
     * @since 1.0.0
553
     * @see OIDC_RP_INITIATED_LOGOUT_OPTIONS
554
     * @see https://openid.net/specs/openid-connect-rpinitiated-1_0.html
555
     */
556
    public function getOpenIdConnectRpInitiatedLogout();
557
558
    /**
559
     * @param int $rpInitiatedLogout Configure RP Initiated Logout.
560
     * @return $this
561
     * @since 1.0.0
562
     * @see OIDC_RP_INITIATED_LOGOUT_OPTIONS
563
     * @see https://openid.net/specs/openid-connect-rpinitiated-1_0.html
564
     */
565
    public function setOpenIdConnectRpInitiatedLogout($rpInitiatedLogout);
566
567
    /**
568
     * The encryption algorithm to use for the OpenID Connect Userinfo Endpoint. When `null`, no encryption is applied.
569
     * @see https://openid.net/specs/openid-connect-registration-1_0.html#ClientMetadata
570
     * @see https://datatracker.ietf.org/doc/html/rfc7518
571
     * @return string|null
572
     * @since 1.0.0
573
     */
574
    public function getOpenIdConnectUserinfoEncryptedResponseAlg();
575
576
    /**
577
     * Set the encryption algorithm to use for the OpenID Connect Userinfo Endpoint.
578
     * When `null`, no encryption is applied.
579
     * @see https://openid.net/specs/openid-connect-registration-1_0.html#ClientMetadata
580
     * @see https://datatracker.ietf.org/doc/html/rfc7518
581
     * @param string|null $algorithm
582
     * @return $this
583
     * @since 1.0.0
584
     */
585
    public function setOpenIdConnectUserinfoEncryptedResponseAlg($algorithm);
586
587
    /**
588
     * @param string|string[]|array[]|Oauth2ClientScopeInterface[]|Oauth2ScopeInterface[]|null $scopes
589
     * @param ScopeRepositoryInterface $scopeRepository
590
     * @return array{
0 ignored issues
show
Documentation Bug introduced by
The doc comment array{ at position 2 could not be parsed: the token is null at position 2.
Loading history...
591
     *     unaffected: Oauth2ClientScopeInterface[],
592
     *     new: Oauth2ClientScopeInterface[],
593
     *     updated: Oauth2ClientScopeInterface[],
594
     *     deleted: Oauth2ClientScopeInterface[],
595
     * }
596
     * @since 1.0.0
597
     */
598
    public function syncClientScopes($scopes, $scopeRepository);
599
}
600