Passed
Push — master ( 63d167...fb60c6 )
by Rutger
03:11
created

Oauth2BaseModule::setOpenIdConnectScopes()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 3
c 1
b 0
f 0
dl 0
loc 5
ccs 4
cts 4
cp 1
rs 10
cc 1
nc 1
nop 1
crap 1
1
<?php
2
3
namespace rhertogh\Yii2Oauth2Server\base;
4
5
use Lcobucci\JWT\Configuration;
6
use Lcobucci\JWT\Signer\Key\InMemory;
7
use Lcobucci\JWT\Signer\Rsa\Sha256;
8
use League\OAuth2\Server\CryptKey;
9
use rhertogh\Yii2Oauth2Server\components\authorization\client\Oauth2ClientAuthorizationRequest;
10
use rhertogh\Yii2Oauth2Server\components\authorization\client\Oauth2ClientScopeAuthorizationRequest;
11
use rhertogh\Yii2Oauth2Server\components\encryption\Oauth2Cryptographer;
12
use rhertogh\Yii2Oauth2Server\components\factories\encryption\Oauth2EncryptionKeyFactory;
13
use rhertogh\Yii2Oauth2Server\components\factories\grants\Oauth2AuthCodeGrantFactory;
14
use rhertogh\Yii2Oauth2Server\components\factories\grants\Oauth2ClientCredentialsGrantFactory;
15
use rhertogh\Yii2Oauth2Server\components\factories\grants\Oauth2ImplicitGrantFactory;
16
use rhertogh\Yii2Oauth2Server\components\factories\grants\Oauth2PasswordGrantFactory;
17
use rhertogh\Yii2Oauth2Server\components\factories\grants\Oauth2PersonalAccessTokenGrantFactory;
18
use rhertogh\Yii2Oauth2Server\components\factories\grants\Oauth2RefreshTokenGrantFactory;
19
use rhertogh\Yii2Oauth2Server\components\openidconnect\claims\Oauth2OidcClaim;
20
use rhertogh\Yii2Oauth2Server\components\openidconnect\scopes\Oauth2OidcScope;
21
use rhertogh\Yii2Oauth2Server\components\openidconnect\scopes\Oauth2OidcScopeCollection;
22
use rhertogh\Yii2Oauth2Server\components\openidconnect\server\responses\Oauth2OidcBearerTokenResponse;
23
use rhertogh\Yii2Oauth2Server\components\repositories\Oauth2AccessTokenRepository;
24
use rhertogh\Yii2Oauth2Server\components\repositories\Oauth2AuthCodeRepository;
25
use rhertogh\Yii2Oauth2Server\components\repositories\Oauth2ClientRepository;
26
use rhertogh\Yii2Oauth2Server\components\repositories\Oauth2RefreshTokenRepository;
27
use rhertogh\Yii2Oauth2Server\components\repositories\Oauth2ScopeRepository;
28
use rhertogh\Yii2Oauth2Server\components\repositories\Oauth2UserRepository;
29
use rhertogh\Yii2Oauth2Server\components\server\grants\Oauth2AuthCodeGrant;
30
use rhertogh\Yii2Oauth2Server\components\server\grants\Oauth2ClientCredentialsGrant;
31
use rhertogh\Yii2Oauth2Server\components\server\grants\Oauth2ImplicitGrant;
32
use rhertogh\Yii2Oauth2Server\components\server\grants\Oauth2PasswordGrant;
33
use rhertogh\Yii2Oauth2Server\components\server\grants\Oauth2PersonalAccessTokenGrant;
34
use rhertogh\Yii2Oauth2Server\components\server\grants\Oauth2RefreshTokenGrant;
35
use rhertogh\Yii2Oauth2Server\components\server\Oauth2AuthorizationServer;
36
use rhertogh\Yii2Oauth2Server\components\server\Oauth2ResourceServer;
37
use rhertogh\Yii2Oauth2Server\components\server\responses\Oauth2BearerTokenResponse;
38
use rhertogh\Yii2Oauth2Server\controllers\console\client\Oauth2CreateClientAction;
39
use rhertogh\Yii2Oauth2Server\controllers\console\client\Oauth2DeleteClientAction;
40
use rhertogh\Yii2Oauth2Server\controllers\console\client\Oauth2ListClientsAction;
41
use rhertogh\Yii2Oauth2Server\controllers\console\client\Oauth2SetClientSecretAction;
42
use rhertogh\Yii2Oauth2Server\controllers\console\client\Oauth2UpdateClientAction;
43
use rhertogh\Yii2Oauth2Server\controllers\console\client\Oauth2ViewClientAction;
44
use rhertogh\Yii2Oauth2Server\controllers\console\debug\Oauth2DebugConfigAction;
45
use rhertogh\Yii2Oauth2Server\controllers\console\encryption\Oauth2EncryptionKeyUsageAction;
46
use rhertogh\Yii2Oauth2Server\controllers\console\encryption\Oauth2GenerateSecretAction;
47
use rhertogh\Yii2Oauth2Server\controllers\console\encryption\Oauth2RotateEncryptionKeysAction;
48
use rhertogh\Yii2Oauth2Server\controllers\console\migrations\Oauth2GenerateImportMigrationAction;
49
use rhertogh\Yii2Oauth2Server\controllers\console\migrations\Oauth2GenerateMigrationsAction;
50
use rhertogh\Yii2Oauth2Server\controllers\console\Oauth2ClientController;
51
use rhertogh\Yii2Oauth2Server\controllers\console\Oauth2DebugController;
52
use rhertogh\Yii2Oauth2Server\controllers\console\Oauth2EncryptionController;
53
use rhertogh\Yii2Oauth2Server\controllers\console\Oauth2MigrationsController;
54
use rhertogh\Yii2Oauth2Server\controllers\console\Oauth2PersonalAccessTokenController;
55
use rhertogh\Yii2Oauth2Server\controllers\console\PersonalAccessToken\Oauth2GeneratePatAction;
56
use rhertogh\Yii2Oauth2Server\controllers\web\certificates\Oauth2JwksAction;
57
use rhertogh\Yii2Oauth2Server\controllers\web\consent\Oauth2AuthorizeClientAction;
58
use rhertogh\Yii2Oauth2Server\controllers\web\Oauth2CertificatesController;
59
use rhertogh\Yii2Oauth2Server\controllers\web\Oauth2ConsentController;
60
use rhertogh\Yii2Oauth2Server\controllers\web\Oauth2OidcController;
61
use rhertogh\Yii2Oauth2Server\controllers\web\Oauth2ServerController;
62
use rhertogh\Yii2Oauth2Server\controllers\web\Oauth2WellKnownController;
63
use rhertogh\Yii2Oauth2Server\controllers\web\openidconnect\Oauth2OidcEndSessionAction;
64
use rhertogh\Yii2Oauth2Server\controllers\web\openidconnect\Oauth2OidcUserinfoAction;
65
use rhertogh\Yii2Oauth2Server\controllers\web\server\Oauth2AccessTokenAction;
66
use rhertogh\Yii2Oauth2Server\controllers\web\server\Oauth2AuthorizeAction;
67
use rhertogh\Yii2Oauth2Server\controllers\web\server\Oauth2RevokeAction;
68
use rhertogh\Yii2Oauth2Server\controllers\web\wellknown\Oauth2OpenidConfigurationAction;
69
use rhertogh\Yii2Oauth2Server\interfaces\components\authorization\client\Oauth2ClientAuthorizationRequestInterface;
70
use rhertogh\Yii2Oauth2Server\interfaces\components\authorization\client\Oauth2ClientScopeAuthorizationRequestInterface;
71
use rhertogh\Yii2Oauth2Server\interfaces\components\encryption\Oauth2CryptographerInterface;
72
use rhertogh\Yii2Oauth2Server\interfaces\components\factories\encryption\Oauth2EncryptionKeyFactoryInterface;
73
use rhertogh\Yii2Oauth2Server\interfaces\components\factories\grants\Oauth2AuthCodeGrantFactoryInterface;
74
use rhertogh\Yii2Oauth2Server\interfaces\components\factories\grants\Oauth2ClientCredentialsGrantFactoryInterface;
75
use rhertogh\Yii2Oauth2Server\interfaces\components\factories\grants\Oauth2ImplicitGrantFactoryInterface;
76
use rhertogh\Yii2Oauth2Server\interfaces\components\factories\grants\Oauth2PasswordGrantFactoryInterface;
77
use rhertogh\Yii2Oauth2Server\interfaces\components\factories\grants\Oauth2PersonalAccessTokenGrantFactoryInterface;
78
use rhertogh\Yii2Oauth2Server\interfaces\components\factories\grants\Oauth2RefreshTokenGrantFactoryInterface;
79
use rhertogh\Yii2Oauth2Server\interfaces\components\openidconnect\scope\Oauth2OidcClaimInterface;
80
use rhertogh\Yii2Oauth2Server\interfaces\components\openidconnect\scope\Oauth2OidcScopeCollectionInterface;
81
use rhertogh\Yii2Oauth2Server\interfaces\components\openidconnect\scope\Oauth2OidcScopeInterface;
82
use rhertogh\Yii2Oauth2Server\interfaces\components\openidconnect\server\responses\Oauth2OidcBearerTokenResponseInterface;
83
use rhertogh\Yii2Oauth2Server\interfaces\components\repositories\base\Oauth2RepositoryInterface;
84
use rhertogh\Yii2Oauth2Server\interfaces\components\repositories\Oauth2AccessTokenRepositoryInterface;
85
use rhertogh\Yii2Oauth2Server\interfaces\components\repositories\Oauth2AuthCodeRepositoryInterface;
86
use rhertogh\Yii2Oauth2Server\interfaces\components\repositories\Oauth2ClientRepositoryInterface;
87
use rhertogh\Yii2Oauth2Server\interfaces\components\repositories\Oauth2RefreshTokenRepositoryInterface;
88
use rhertogh\Yii2Oauth2Server\interfaces\components\repositories\Oauth2ScopeRepositoryInterface;
89
use rhertogh\Yii2Oauth2Server\interfaces\components\repositories\Oauth2UserRepositoryInterface;
90
use rhertogh\Yii2Oauth2Server\interfaces\components\server\grants\Oauth2AuthCodeGrantInterface;
91
use rhertogh\Yii2Oauth2Server\interfaces\components\server\grants\Oauth2ClientCredentialsGrantInterface;
92
use rhertogh\Yii2Oauth2Server\interfaces\components\server\grants\Oauth2ImplicitGrantInterface;
93
use rhertogh\Yii2Oauth2Server\interfaces\components\server\grants\Oauth2PasswordGrantInterface;
94
use rhertogh\Yii2Oauth2Server\interfaces\components\server\grants\Oauth2PersonalAccessTokenGrantInterface;
95
use rhertogh\Yii2Oauth2Server\interfaces\components\server\grants\Oauth2RefreshTokenGrantInterface;
96
use rhertogh\Yii2Oauth2Server\interfaces\components\server\Oauth2AuthorizationServerInterface;
97
use rhertogh\Yii2Oauth2Server\interfaces\components\server\Oauth2ResourceServerInterface;
98
use rhertogh\Yii2Oauth2Server\interfaces\components\server\responses\Oauth2BearerTokenResponseInterface;
99
use rhertogh\Yii2Oauth2Server\interfaces\controllers\console\client\Oauth2CreateClientActionInterface;
100
use rhertogh\Yii2Oauth2Server\interfaces\controllers\console\client\Oauth2DeleteClientActionInterface;
101
use rhertogh\Yii2Oauth2Server\interfaces\controllers\console\client\Oauth2ListClientsActionInterface;
102
use rhertogh\Yii2Oauth2Server\interfaces\controllers\console\client\Oauth2SetClientSecretActionInterface;
103
use rhertogh\Yii2Oauth2Server\interfaces\controllers\console\client\Oauth2UpdateClientActionInterface;
104
use rhertogh\Yii2Oauth2Server\interfaces\controllers\console\client\Oauth2ViewClientActionInterface;
105
use rhertogh\Yii2Oauth2Server\interfaces\controllers\console\debug\Oauth2DebugConfigActionInterface;
106
use rhertogh\Yii2Oauth2Server\interfaces\controllers\console\encryption\Oauth2EncryptionKeyUsageActionInterface;
107
use rhertogh\Yii2Oauth2Server\interfaces\controllers\console\encryption\Oauth2GenerateSecretActionInterface;
108
use rhertogh\Yii2Oauth2Server\interfaces\controllers\console\encryption\Oauth2RotateEncryptionKeysActionInterface;
109
use rhertogh\Yii2Oauth2Server\interfaces\controllers\console\migrations\Oauth2GenerateImportMigrationActionInterface;
110
use rhertogh\Yii2Oauth2Server\interfaces\controllers\console\migrations\Oauth2GenerateMigrationsActionInterface;
111
use rhertogh\Yii2Oauth2Server\interfaces\controllers\console\Oauth2ClientControllerInterface;
112
use rhertogh\Yii2Oauth2Server\interfaces\controllers\console\Oauth2DebugControllerInterface;
113
use rhertogh\Yii2Oauth2Server\interfaces\controllers\console\Oauth2EncryptionControllerInterface;
114
use rhertogh\Yii2Oauth2Server\interfaces\controllers\console\Oauth2MigrationsControllerInterface;
115
use rhertogh\Yii2Oauth2Server\interfaces\controllers\console\Oauth2PersonalAccessTokenControllerInterface;
116
use rhertogh\Yii2Oauth2Server\interfaces\controllers\console\PersonalAccessToken\Oauth2GeneratePatActionInterface;
117
use rhertogh\Yii2Oauth2Server\interfaces\controllers\web\certificates\Oauth2JwksActionInterface;
118
use rhertogh\Yii2Oauth2Server\interfaces\controllers\web\consent\Oauth2AuthorizeClientActionInterface;
119
use rhertogh\Yii2Oauth2Server\interfaces\controllers\web\Oauth2CertificatesControllerInterface;
120
use rhertogh\Yii2Oauth2Server\interfaces\controllers\web\Oauth2ConsentControllerInterface;
121
use rhertogh\Yii2Oauth2Server\interfaces\controllers\web\Oauth2OidcControllerInterface;
122
use rhertogh\Yii2Oauth2Server\interfaces\controllers\web\Oauth2ServerControllerInterface;
123
use rhertogh\Yii2Oauth2Server\interfaces\controllers\web\Oauth2WellKnownControllerInterface;
124
use rhertogh\Yii2Oauth2Server\interfaces\controllers\web\openidconnect\Oauth2OidcEndSessionActionInterface;
125
use rhertogh\Yii2Oauth2Server\interfaces\controllers\web\openidconnect\Oauth2OidcUserinfoActionInterface;
126
use rhertogh\Yii2Oauth2Server\interfaces\controllers\web\server\Oauth2AccessTokenActionInterface;
127
use rhertogh\Yii2Oauth2Server\interfaces\controllers\web\server\Oauth2AuthorizeActionInterface;
128
use rhertogh\Yii2Oauth2Server\interfaces\controllers\web\server\Oauth2RevokeActionInterface;
129
use rhertogh\Yii2Oauth2Server\interfaces\controllers\web\wellknown\Oauth2OpenidConfigurationActionInterface;
130
use rhertogh\Yii2Oauth2Server\interfaces\models\external\user\Oauth2OidcUserInterface;
131
use rhertogh\Yii2Oauth2Server\interfaces\models\Oauth2AccessTokenInterface;
132
use rhertogh\Yii2Oauth2Server\interfaces\models\Oauth2AccessTokenScopeInterface;
133
use rhertogh\Yii2Oauth2Server\interfaces\models\Oauth2AuthCodeInterface;
134
use rhertogh\Yii2Oauth2Server\interfaces\models\Oauth2AuthCodeScopeInterface;
135
use rhertogh\Yii2Oauth2Server\interfaces\models\Oauth2ClientInterface;
136
use rhertogh\Yii2Oauth2Server\interfaces\models\Oauth2ClientScopeInterface;
137
use rhertogh\Yii2Oauth2Server\interfaces\models\Oauth2RefreshTokenInterface;
138
use rhertogh\Yii2Oauth2Server\interfaces\models\Oauth2ScopeInterface;
139
use rhertogh\Yii2Oauth2Server\interfaces\models\Oauth2UserClientInterface;
140
use rhertogh\Yii2Oauth2Server\interfaces\models\Oauth2UserClientScopeInterface;
141
use rhertogh\Yii2Oauth2Server\interfaces\models\queries\Oauth2AccessTokenQueryInterface;
142
use rhertogh\Yii2Oauth2Server\interfaces\models\queries\Oauth2AccessTokenScopeQueryInterface;
143
use rhertogh\Yii2Oauth2Server\interfaces\models\queries\Oauth2AuthCodeQueryInterface;
144
use rhertogh\Yii2Oauth2Server\interfaces\models\queries\Oauth2AuthCodeScopeQueryInterface;
145
use rhertogh\Yii2Oauth2Server\interfaces\models\queries\Oauth2ClientQueryInterface;
146
use rhertogh\Yii2Oauth2Server\interfaces\models\queries\Oauth2ClientScopeQueryInterface;
147
use rhertogh\Yii2Oauth2Server\interfaces\models\queries\Oauth2RefreshTokenQueryInterface;
148
use rhertogh\Yii2Oauth2Server\interfaces\models\queries\Oauth2ScopeQueryInterface;
149
use rhertogh\Yii2Oauth2Server\interfaces\models\queries\Oauth2UserClientQueryInterface;
150
use rhertogh\Yii2Oauth2Server\interfaces\models\queries\Oauth2UserClientScopeQueryInterface;
151
use rhertogh\Yii2Oauth2Server\models\Oauth2AccessToken;
152
use rhertogh\Yii2Oauth2Server\models\Oauth2AccessTokenScope;
153
use rhertogh\Yii2Oauth2Server\models\Oauth2AuthCode;
154
use rhertogh\Yii2Oauth2Server\models\Oauth2AuthCodeScope;
155
use rhertogh\Yii2Oauth2Server\models\Oauth2Client;
156
use rhertogh\Yii2Oauth2Server\models\Oauth2ClientScope;
157
use rhertogh\Yii2Oauth2Server\models\Oauth2RefreshToken;
158
use rhertogh\Yii2Oauth2Server\models\Oauth2Scope;
159
use rhertogh\Yii2Oauth2Server\models\Oauth2UserClient;
160
use rhertogh\Yii2Oauth2Server\models\Oauth2UserClientScope;
161
use rhertogh\Yii2Oauth2Server\models\queries\Oauth2AccessTokenQuery;
162
use rhertogh\Yii2Oauth2Server\models\queries\Oauth2AccessTokenScopeQuery;
163
use rhertogh\Yii2Oauth2Server\models\queries\Oauth2AuthCodeQuery;
164
use rhertogh\Yii2Oauth2Server\models\queries\Oauth2AuthCodeScopeQuery;
165
use rhertogh\Yii2Oauth2Server\models\queries\Oauth2ClientQuery;
166
use rhertogh\Yii2Oauth2Server\models\queries\Oauth2ClientScopeQuery;
167
use rhertogh\Yii2Oauth2Server\models\queries\Oauth2RefreshTokenQuery;
168
use rhertogh\Yii2Oauth2Server\models\queries\Oauth2ScopeQuery;
169
use rhertogh\Yii2Oauth2Server\models\queries\Oauth2UserClientQuery;
170
use rhertogh\Yii2Oauth2Server\models\queries\Oauth2UserClientScopeQuery;
171
use Yii;
172
use yii\base\InvalidCallException;
173
use yii\base\InvalidConfigException;
174
use yii\base\Module;
175
176
/**
177
 * @property Oauth2OidcScopeCollectionInterface|array|callable|string $openIdConnectScopes;
178
 */
179
abstract class Oauth2BaseModule extends Module
180
{
181
    # region Supported grant types.
182
    # Note: These should match League\OAuth2\Server\Grant\GrantTypeInterface::getIdentifier() for their respective type.
183
    /**
184
     * "authorization_code" Grant Type.
185
     * @since 1.0.0
186
     */
187
    public const GRANT_TYPE_IDENTIFIER_AUTH_CODE = 'authorization_code';
188
    /**
189
     * "client_credentials" Grant Type.
190
     * @since 1.0.0
191
     */
192
    public const GRANT_TYPE_IDENTIFIER_CLIENT_CREDENTIALS = 'client_credentials';
193
    /**
194
     * "refresh_token" Grant Type.
195
     * @since 1.0.0
196
     */
197
    public const GRANT_TYPE_IDENTIFIER_REFRESH_TOKEN = 'refresh_token';
198
    /**
199
     * "implicit" Grant Type. Note: This is a legacy Grant Type.
200
     * @since 1.0.0
201
     */
202
    public const GRANT_TYPE_IDENTIFIER_IMPLICIT = 'implicit';
203
    /**
204
     * "password" Grant Type. Note: This is a legacy Grant Type.
205
     * @since 1.0.0
206
     */
207
    public const GRANT_TYPE_IDENTIFIER_PASSWORD = 'password';
208
209
    /**
210
     * "personal_access_token" Grant Type. Note: This is a custom grant type and not part of the Oauth2 specification.
211
     * @since 1.0.0
212
     */
213
    public const GRANT_TYPE_IDENTIFIER_PERSONAL_ACCESS_TOKEN = 'personal_access_token';
214
215
    /**
216
     * Supported grant type identifiers
217
     * @since 1.0.0
218
     */
219
    public const GRANT_TYPE_IDENTIFIERS = [
220
        self::GRANT_TYPE_IDENTIFIER_AUTH_CODE,
221
        self::GRANT_TYPE_IDENTIFIER_CLIENT_CREDENTIALS,
222
        self::GRANT_TYPE_IDENTIFIER_REFRESH_TOKEN,
223
        self::GRANT_TYPE_IDENTIFIER_IMPLICIT,
224
        self::GRANT_TYPE_IDENTIFIER_PASSWORD,
225
        self::GRANT_TYPE_IDENTIFIER_PERSONAL_ACCESS_TOKEN,
226
    ];
227
    # endregion Supported grant types
228
229
    # region Numeric IDs for Supported grant types
230
    /**
231
     * Numeric id for "authorization_code" Grant Type.
232
     * @since 1.0.0
233
     */
234
    public const GRANT_TYPE_AUTH_CODE = 1;
235
    /**
236
     * Numeric id for "client_credentials" Grant Type.
237
     * @since 1.0.0
238
     */
239
    public const GRANT_TYPE_CLIENT_CREDENTIALS = 2;
240
    /**
241
     * Numeric id for "refresh_token" Grant Type.
242
     * @since 1.0.0
243
     */
244
    public const GRANT_TYPE_REFRESH_TOKEN = 4;
245
    /**
246
     * Numeric id for "implicit" Grant Type. Note: This is a legacy Grant Type.
247
     * @since 1.0.0
248
     */
249
    public const GRANT_TYPE_PASSWORD = 1024; // Legacy Grant.
250
    /**
251
     * Numeric id for "password" Grant Type. Note: This is a legacy Grant Type.
252
     * @since 1.0.0
253
     */
254
    public const GRANT_TYPE_IMPLICIT = 2048; // Legacy Grant.
255
    /**
256
     * Numeric id for "personal_access_token" Grant Type.
257
     * Note: This is a custom grant type and not part of the Oauth2 specification.
258
     * @since 1.0.0
259
     */
260
    public const GRANT_TYPE_PERSONAL_ACCESS_TOKEN = 4096;
261
    # endregion Numeric IDs for Supported grant types
262
263
    /**
264
     * Mapping between Grant Type identifier and its numeric id.
265
     * @since 1.0.0
266
     */
267
    public const GRANT_TYPE_MAPPING = [
268
        self::GRANT_TYPE_IDENTIFIER_AUTH_CODE => self::GRANT_TYPE_AUTH_CODE,
269
        self::GRANT_TYPE_IDENTIFIER_CLIENT_CREDENTIALS => self::GRANT_TYPE_CLIENT_CREDENTIALS,
270
        self::GRANT_TYPE_IDENTIFIER_REFRESH_TOKEN => self::GRANT_TYPE_REFRESH_TOKEN,
271
        self::GRANT_TYPE_IDENTIFIER_PASSWORD => self::GRANT_TYPE_PASSWORD, // Legacy Grant.
272
        self::GRANT_TYPE_IDENTIFIER_IMPLICIT => self::GRANT_TYPE_IMPLICIT, // Legacy Grant.
273
        self::GRANT_TYPE_IDENTIFIER_PERSONAL_ACCESS_TOKEN => self::GRANT_TYPE_PERSONAL_ACCESS_TOKEN, // Custom Grant.
274
    ];
275
276
    /**
277
     * Events
278
     */
279
    public const EVENT_BEFORE_CLIENT_AUTHORIZATION = 'Oauth2Server.Client.Authorization.Before';
280
    public const EVENT_BEFORE_AFTER_AUTHORIZATION = 'Oauth2Server.Client.Authorization.After';
281
    public const EVENT_BEFORE_AUTH_CODE_ISSUANCE = 'Oauth2Server.Grant.AuthCode.Issuance.Before';
282
    public const EVENT_AFTER_AUTH_CODE_ISSUANCE = 'Oauth2Server.Grant.AuthCode.Issuance.After';
283
    public const EVENT_BEFORE_ACCESS_TOKEN_ISSUANCE = 'Oauth2Server.Grant.AccessToken.Issuance.Before';
284
    public const EVENT_AFTER_ACCESS_TOKEN_ISSUANCE = 'Oauth2Server.Grant.AccessToken.Issuance.After';
285
    public const EVENT_BEFORE_REFRESH_TOKEN_ISSUANCE = 'Oauth2Server.Grant.RefreshToken.Issuance.Before';
286
    public const EVENT_AFTER_REFRESH_TOKEN_ISSUANCE = 'Oauth2Server.Grant.RefreshToken.Issuance.After';
287
288
    /**
289
     * Never show  User Account Selection for OpenID Connect.
290
     * @since 1.0.0
291
     */
292
    public const USER_ACCOUNT_SELECTION_DISABLED = 0;
293
    /**
294
     * Show User Account Selection upon client request for OpenID Connect.
295
     * @since 1.0.0
296
     */
297
    public const USER_ACCOUNT_SELECTION_UPON_CLIENT_REQUEST = 1;
298
    /**
299
     * Always show User Account Selection for OpenID Connect.
300
     * @since 1.0.0
301
     */
302
    public const USER_ACCOUNT_SELECTION_ALWAYS = 2;
303
304
    /**
305
     * Human-readable name for user account selection options.
306
     * @since 1.0.0
307
     */
308
    public const USER_ACCOUNT_SELECTION_NAMES = [
309
        self::USER_ACCOUNT_SELECTION_DISABLED => 'disabled',
310
        self::USER_ACCOUNT_SELECTION_UPON_CLIENT_REQUEST => 'upon_client_request',
311
        self::USER_ACCOUNT_SELECTION_ALWAYS => 'always',
312
    ];
313
314
    /**
315
     * Default factory interface per grant type
316
     * @since 1.0.0
317
     */
318
    protected const DEFAULT_GRANT_TYPE_FACTORIES = [
319
        self::GRANT_TYPE_AUTH_CODE => Oauth2AuthCodeGrantFactoryInterface::class,
320
        self::GRANT_TYPE_CLIENT_CREDENTIALS => Oauth2ClientCredentialsGrantFactoryInterface::class,
321
        self::GRANT_TYPE_REFRESH_TOKEN => Oauth2RefreshTokenGrantFactoryInterface::class,
322
        self::GRANT_TYPE_IMPLICIT => Oauth2ImplicitGrantFactoryInterface::class, // Legacy Grant.
323
        self::GRANT_TYPE_PASSWORD => Oauth2PasswordGrantFactoryInterface::class, // Legacy Grant.
324
        self::GRANT_TYPE_PERSONAL_ACCESS_TOKEN => Oauth2PersonalAccessTokenGrantFactoryInterface::class, // Custom Grant.
325
    ];
326
327
    /**
328
     * Default mapping for interfaces
329
     * @since 1.0.0
330
     */
331
    protected const DEFAULT_INTERFACE_IMPLEMENTATIONS = [
332
        # Repositories
333
        Oauth2AccessTokenRepositoryInterface::class => Oauth2AccessTokenRepository::class,
334
        Oauth2AuthCodeRepositoryInterface::class => Oauth2AuthCodeRepository::class,
335
        Oauth2ClientRepositoryInterface::class => Oauth2ClientRepository::class,
336
        Oauth2RefreshTokenRepositoryInterface::class => Oauth2RefreshTokenRepository::class,
337
        Oauth2ScopeRepositoryInterface::class => Oauth2ScopeRepository::class,
338
        Oauth2UserRepositoryInterface::class => Oauth2UserRepository::class,
339
        # Models
340
        Oauth2AccessTokenInterface::class => Oauth2AccessToken::class,
341
        Oauth2AccessTokenScopeInterface::class => Oauth2AccessTokenScope::class,
342
        Oauth2AuthCodeInterface::class => Oauth2AuthCode::class,
343
        Oauth2AuthCodeScopeInterface::class => Oauth2AuthCodeScope::class,
344
        Oauth2ClientInterface::class => Oauth2Client::class,
345
        Oauth2ClientScopeInterface::class => Oauth2ClientScope::class,
346
        Oauth2RefreshTokenInterface::class => Oauth2RefreshToken::class,
347
        Oauth2ScopeInterface::class => Oauth2Scope::class,
348
        Oauth2UserClientInterface::class => Oauth2UserClient::class,
349
        Oauth2UserClientScopeInterface::class => Oauth2UserClientScope::class,
350
        # Queries
351
        Oauth2AccessTokenQueryInterface::class => Oauth2AccessTokenQuery::class,
352
        Oauth2AccessTokenScopeQueryInterface::class => Oauth2AccessTokenScopeQuery::class,
353
        Oauth2AuthCodeQueryInterface::class => Oauth2AuthCodeQuery::class,
354
        Oauth2AuthCodeScopeQueryInterface::class => Oauth2AuthCodeScopeQuery::class,
355
        Oauth2ClientQueryInterface::class => Oauth2ClientQuery::class,
356
        Oauth2ClientScopeQueryInterface::class => Oauth2ClientScopeQuery::class,
357
        Oauth2RefreshTokenQueryInterface::class => Oauth2RefreshTokenQuery::class,
358
        Oauth2ScopeQueryInterface::class => Oauth2ScopeQuery::class,
359
        Oauth2UserClientQueryInterface::class => Oauth2UserClientQuery::class,
360
        Oauth2UserClientScopeQueryInterface::class => Oauth2UserClientScopeQuery::class,
361
        # Factories
362
        Oauth2AuthCodeGrantFactoryInterface::class => Oauth2AuthCodeGrantFactory::class,
363
        Oauth2ClientCredentialsGrantFactoryInterface::class => Oauth2ClientCredentialsGrantFactory::class,
364
        Oauth2RefreshTokenGrantFactoryInterface::class => Oauth2RefreshTokenGrantFactory::class,
365
        Oauth2ImplicitGrantFactoryInterface::class => Oauth2ImplicitGrantFactory::class,
366
        Oauth2PasswordGrantFactoryInterface::class => Oauth2PasswordGrantFactory::class,
367
        Oauth2PersonalAccessTokenGrantFactoryInterface::class => Oauth2PersonalAccessTokenGrantFactory::class,
368
        Oauth2EncryptionKeyFactoryInterface::class => Oauth2EncryptionKeyFactory::class,
369
        # Controllers (web)
370
        Oauth2ServerControllerInterface::class => Oauth2ServerController::class,
371
        Oauth2ConsentControllerInterface::class => Oauth2ConsentController::class,
372
        Oauth2WellKnownControllerInterface::class => Oauth2WellKnownController::class,
373
        Oauth2CertificatesControllerInterface::class => Oauth2CertificatesController::class,
374
        Oauth2OidcControllerInterface::class => Oauth2OidcController::class,
375
        # Controllers (console)
376
        Oauth2PersonalAccessTokenControllerInterface::class => Oauth2PersonalAccessTokenController::class,
377
        Oauth2MigrationsControllerInterface::class => Oauth2MigrationsController::class,
378
        Oauth2EncryptionControllerInterface::class => Oauth2EncryptionController::class,
379
        Oauth2DebugControllerInterface::class => Oauth2DebugController::class,
380
        Oauth2ClientControllerInterface::class => Oauth2ClientController::class,
381
        # Actions (web)
382
        Oauth2OpenidConfigurationActionInterface::class => Oauth2OpenidConfigurationAction::class,
383
        Oauth2RevokeActionInterface::class => Oauth2RevokeAction::class,
384
        Oauth2AuthorizeActionInterface::class => Oauth2AuthorizeAction::class,
385
        Oauth2AccessTokenActionInterface::class => Oauth2AccessTokenAction::class,
386
        Oauth2OidcUserinfoActionInterface::class => Oauth2OidcUserinfoAction::class,
387
        Oauth2OidcEndSessionActionInterface::class => Oauth2OidcEndSessionAction::class,
388
        Oauth2AuthorizeClientActionInterface::class => Oauth2AuthorizeClientAction::class,
389
        Oauth2JwksActionInterface::class => Oauth2JwksAction::class,
390
        # Actions (console)
391
        Oauth2GeneratePatActionInterface::class => Oauth2GeneratePatAction::class,
392
        Oauth2GenerateMigrationsActionInterface::class => Oauth2GenerateMigrationsAction::class,
393
        Oauth2GenerateImportMigrationActionInterface::class => Oauth2GenerateImportMigrationAction::class,
394
        Oauth2RotateEncryptionKeysActionInterface::class => Oauth2RotateEncryptionKeysAction::class,
395
        Oauth2GenerateSecretActionInterface::class => Oauth2GenerateSecretAction::class,
396
        Oauth2EncryptionKeyUsageActionInterface::class => Oauth2EncryptionKeyUsageAction::class,
397
        Oauth2DebugConfigActionInterface::class => Oauth2DebugConfigAction::class,
398
        Oauth2ViewClientActionInterface::class => Oauth2ViewClientAction::class,
399
        Oauth2UpdateClientActionInterface::class => Oauth2UpdateClientAction::class,
400
        Oauth2SetClientSecretActionInterface::class => Oauth2SetClientSecretAction::class,
401
        Oauth2ListClientsActionInterface::class => Oauth2ListClientsAction::class,
402
        Oauth2DeleteClientActionInterface::class => Oauth2DeleteClientAction::class,
403
        Oauth2CreateClientActionInterface::class => Oauth2CreateClientAction::class,
404
        # Components (Server)
405
        Oauth2AuthorizationServerInterface::class => Oauth2AuthorizationServer::class,
406
        Oauth2ResourceServerInterface::class => Oauth2ResourceServer::class,
407
        # Components (Server Grants)
408
        Oauth2AuthCodeGrantInterface::class => Oauth2AuthCodeGrant::class,
409
        Oauth2ClientCredentialsGrantInterface::class => Oauth2ClientCredentialsGrant::class,
410
        Oauth2ImplicitGrantInterface::class => Oauth2ImplicitGrant::class,
411
        Oauth2PasswordGrantInterface::class => Oauth2PasswordGrant::class,
412
        Oauth2RefreshTokenGrantInterface::class => Oauth2RefreshTokenGrant::class,
413
        Oauth2PersonalAccessTokenGrantInterface::class => Oauth2PersonalAccessTokenGrant::class,
414
        # Components (Responses)
415
        Oauth2BearerTokenResponseInterface::class => Oauth2BearerTokenResponse::class,
416
        # Components (OpenID Connect)
417
        Oauth2OidcScopeCollectionInterface::class => Oauth2OidcScopeCollection::class,
418
        Oauth2OidcScopeInterface::class => Oauth2OidcScope::class,
419
        Oauth2OidcClaimInterface::class => Oauth2OidcClaim::class,
420
        Oauth2OidcBearerTokenResponseInterface::class => Oauth2OidcBearerTokenResponse::class,
421
        # Components (Misc)
422
        Oauth2CryptographerInterface::class => Oauth2Cryptographer::class,
423
        Oauth2ClientAuthorizationRequestInterface::class => Oauth2ClientAuthorizationRequest::class,
424
        Oauth2ClientScopeAuthorizationRequestInterface::class => Oauth2ClientScopeAuthorizationRequest::class,
425
    ];
426
427
    /**
428
     * Cache for the Repositories
429
     * @var Oauth2RepositoryInterface[]
430
     * @since 1.0.0
431
     */
432
    protected $_repositories;
433
434
    /**
435
     * Claims for the current request
436
     * @var mixed[]
437
     * @since 1.0.0
438
     */
439
    protected $_oauthClaims;
440
441
    /**
442
     * Configuration for the enabled OpenID Connect scopes.
443
     * @var Oauth2OidcScopeCollectionInterface|array|callable|string
444
     * @since 1.0.0
445
     */
446
    protected $_openIdConnectScopes = Oauth2OidcScopeCollectionInterface::OPENID_CONNECT_DEFAULT_SCOPES;
447
448
    /**
449
     * Cache for the OpenID Connect scope collection.
450
     * @var Oauth2OidcScopeCollectionInterface|null
451
     * @since 1.0.0
452
     */
453
    protected $_oidcScopeCollection = null;
454
455
    //////////////////////////
456
    /// Abstract Functions ///
457
    //////////////////////////
458
459
    /**
460
     * @return Oauth2OidcScopeCollectionInterface The supported scopes for OpenID Connect
461
     * @since 1.0.0
462
     */
463
    abstract public function getOidcScopeCollection();
464
465
    /**
466
     * Get a specific claim from an authorized Request
467
     * @param string $attribute
468
     * @param mixed|null $default
469
     * @return mixed|null The value of the claim or the $default value if not set.
470
     * @throws InvalidCallException
471
     * @since 1.0.0
472
     */
473
    abstract protected function getRequestOauthClaim($attribute, $default = null);
474
475
476
    ////////////////////////
477
    /// Static Functions ///
478
    ////////////////////////
479
480
    /**
481
     * Convert a grant type identifier to its numeric id
482
     * @param string $grantTypeIdentifier
483
     * @return int|null
484
     * @since 1.0.0
485
     */
486 1
    public static function getGrantTypeId($grantTypeIdentifier)
487
    {
488 1
        return static::GRANT_TYPE_MAPPING[$grantTypeIdentifier] ?? null;
489
    }
490
491
    /**
492
     * Convert a numeric grant type id to its string identifier
493
     * @param int $grantTypeId
494
     * @return int|null
495
     * @since 1.0.0
496
     */
497 1
    public static function getGrantTypeIdentifier($grantTypeId)
498
    {
499 1
        return array_flip(static::GRANT_TYPE_MAPPING)[$grantTypeId] ?? null;
500
    }
501
502
    /**
503
     * Convert Grant Type IDs to an array of their identifiers
504
     * @param int $grantTypeIDs
505
     * @return array
506
     */
507
    public static function getGrantTypeIdentifiers($grantTypeIDs)
508
    {
509
        $identifiers = [];
510
        foreach (static::GRANT_TYPE_MAPPING as $identifier => $id) {
511
            if ($grantTypeIDs & $id) {
512
                $identifiers[] = $identifier;
513
            }
514
        }
515
        return $identifiers;
516
    }
517
518
    /////////////////////////
519
    /// Getters & Setters ///
520
    /////////////////////////
521
522
    /**
523
     * @return Oauth2AccessTokenRepositoryInterface The Access Token Repository
524
     * @since 1.0.0
525
     */
526 7
    public function getAccessTokenRepository(): Oauth2AccessTokenRepositoryInterface
527
    {
528 7
        return $this->getRepository(Oauth2AccessTokenRepositoryInterface::class);
529
    }
530
531
    /**
532
     * @return $this
533
     * @since 1.0.0
534
     */
535 1
    public function setAccessTokenRepository(Oauth2AccessTokenRepositoryInterface $repository)
536
    {
537 1
        $this->setRepository(Oauth2AccessTokenRepositoryInterface::class, $repository);
538 1
        return $this;
539
    }
540
541
    /**
542
     * @return Oauth2AuthCodeRepositoryInterface The Auth Code Repository
543
     * @since 1.0.0
544
     */
545 7
    public function getAuthCodeRepository(): Oauth2AuthCodeRepositoryInterface
546
    {
547 7
        return $this->getRepository(Oauth2AuthCodeRepositoryInterface::class);
548
    }
549
550
    /**
551
     * @return $this
552
     * @since 1.0.0
553
     */
554 1
    public function setAuthCodeRepository(Oauth2AuthCodeRepositoryInterface $repository)
555
    {
556 1
        $this->setRepository(Oauth2AuthCodeRepositoryInterface::class, $repository);
557 1
        return $this;
558
    }
559
560
    /**
561
     * @return Oauth2ClientRepositoryInterface The Client Repository
562
     * @since 1.0.0
563
     */
564 6
    public function getClientRepository(): Oauth2ClientRepositoryInterface
565
    {
566 6
        return $this->getRepository(Oauth2ClientRepositoryInterface::class);
567
    }
568
569
    /**
570
     * @return $this
571
     * @since 1.0.0
572
     */
573 1
    public function setClientRepository(Oauth2ClientRepositoryInterface $repository)
574
    {
575 1
        $this->setRepository(Oauth2ClientRepositoryInterface::class, $repository);
576 1
        return $this;
577
    }
578
579
    /**
580
     * @return Oauth2RefreshTokenRepositoryInterface The Refresh Token Repository
581
     * @since 1.0.0
582
     */
583 9
    public function getRefreshTokenRepository(): Oauth2RefreshTokenRepositoryInterface
584
    {
585 9
        return $this->getRepository(Oauth2RefreshTokenRepositoryInterface::class);
586
    }
587
588
    /**
589
     * @return $this
590
     * @since 1.0.0
591
     */
592 1
    public function setRefreshTokenRepository(Oauth2RefreshTokenRepositoryInterface $repository)
593
    {
594 1
        $this->setRepository(Oauth2RefreshTokenRepositoryInterface::class, $repository);
595 1
        return $this;
596
    }
597
598
    /**
599
     * @return Oauth2ScopeRepositoryInterface The Scope Repository
600
     * @since 1.0.0
601
     */
602 6
    public function getScopeRepository(): Oauth2ScopeRepositoryInterface
603
    {
604 6
        return $this->getRepository(Oauth2ScopeRepositoryInterface::class);
605
    }
606
607
    /**
608
     * @return $this
609
     * @since 1.0.0
610
     */
611 1
    public function setScopeRepository(Oauth2ScopeRepositoryInterface $repository)
612
    {
613 1
        $this->setRepository(Oauth2ScopeRepositoryInterface::class, $repository);
614 1
        return $this;
615
    }
616
617
    /**
618
     * @return Oauth2UserRepositoryInterface The User Repository
619
     * @since 1.0.0
620
     */
621 8
    public function getUserRepository(): Oauth2UserRepositoryInterface
622
    {
623 8
        return $this->getRepository(Oauth2UserRepositoryInterface::class);
624
    }
625
626
    /**
627
     * @return $this
628
     * @since 1.0.0
629
     */
630 1
    public function setUserRepository(Oauth2UserRepositoryInterface $repository)
631
    {
632 1
        $this->setRepository(Oauth2UserRepositoryInterface::class, $repository);
633 1
        return $this;
634
    }
635
636
    /**
637
     * Get a repository by class.
638
     * @template T of Oauth2RepositoryInterface
639
     * @param class-string<T> $class
0 ignored issues
show
Documentation Bug introduced by
The doc comment class-string<T> at position 0 could not be parsed: Unknown type name 'class-string' at position 0 in class-string<T>.
Loading history...
640
     * @return T
641
     * @throws \yii\base\InvalidConfigException
642
     * @since 1.0.0
643
     */
644 20
    protected function getRepository($class)
645
    {
646 20
        if (empty($this->_repositories[$class])) {
647 14
            $this->setRepository($class, Yii::createObject($class));
648
        }
649
650 20
        return $this->_repositories[$class];
651
    }
652
653
    /**
654
     * @param class-string<Oauth2RepositoryInterface> $class
0 ignored issues
show
Documentation Bug introduced by
The doc comment class-string<Oauth2RepositoryInterface> at position 0 could not be parsed: Unknown type name 'class-string' at position 0 in class-string<Oauth2RepositoryInterface>.
Loading history...
655
     * @return $this
656
     * @throws InvalidConfigException
657
     */
658 20
    protected function setRepository($class, $repository)
659
    {
660 20
        $repository->setModule($this);
661 20
        $this->_repositories[$class] = $repository;
662
663 20
        return $this;
664
    }
665
666
    /**
667
     * Get the Oauth 'access_token_id' claim.
668
     * @return string|null
669
     * @see validateAuthenticatedRequest()
670
     * @since 1.0.0
671
     */
672 2
    public function getRequestOauthAccessTokenIdentifier()
673
    {
674 2
        return $this->getRequestOauthClaim('oauth_access_token_id');
675
    }
676
677
    /**
678
     * Get the Oauth 'client_id' claim.
679
     * @return string
680
     * @see validateAuthenticatedRequest()
681
     * @since 1.0.0
682
     */
683 1
    public function getRequestOauthClientIdentifier()
684
    {
685 1
        return $this->getRequestOauthClaim('oauth_client_id');
686
    }
687
688
    /**
689
     * Get the Oauth 'user_id' claim.
690
     * @return mixed|null
691
     * @see validateAuthenticatedRequest()
692
     * @since 1.0.0
693
     */
694 1
    public function getRequestOauthUserId()
695
    {
696 1
        return $this->getRequestOauthClaim('oauth_user_id');
697
    }
698
699
    /**
700
     * Get the Oauth 'scopes' claim.
701
     * @return string[]
702
     * @see validateAuthenticatedRequest()
703
     * @since 1.0.0
704
     */
705 2
    public function getRequestOauthScopeIdentifiers()
706
    {
707 2
        return $this->getRequestOauthClaim('oauth_scopes', []);
708
    }
709
710
    /**
711
     * Check if the Request has the specified scope.
712
     * @param string $scopeIdentifier
713
     * @param bool $strict If strict is `false` and the user is not authenticated via Oauth, return true.
714
     * @return bool
715
     * @see validateAuthenticatedRequest()
716
     * @since 1.0.0
717
     */
718 1
    public function requestHasScope($scopeIdentifier, $strict = true)
719
    {
720 1
        if (!$strict && ($this->getRequestOauthAccessTokenIdentifier() === null)) {
721
            //If not strict and the user is not authenticated via Oauth, allow the scope.
722 1
            return true;
723
        }
724 1
        return in_array($scopeIdentifier, $this->getRequestOauthScopeIdentifiers());
725
    }
726
727
    /**
728
     * Get the configuration for the enabled OpenID Connect scopes.
729
     * @return Oauth2OidcScopeCollectionInterface|array|callable|string
730
     * @see getOidcScopeCollection()
731
     * @since 1.0.0
732
     */
733 3
    public function getOpenIdConnectScopes()
734
    {
735 3
        return $this->_openIdConnectScopes;
736
    }
737
738
    /**
739
     * Set the configuration for the enabled OpenID Connect scopes.
740
     * @return $this
741
     * @see getOidcScopeCollection()
742
     * @since 1.0.0
743
     */
744 2
    public function setOpenIdConnectScopes($openIdConnectScopes)
745
    {
746 2
        $this->_openIdConnectScopes = $openIdConnectScopes;
747 2
        $this->_oidcScopeCollection = null;
748 2
        return $this;
749
    }
750
751
    ////////////////////////
752
    /// Public Functions ///
753
    ////////////////////////
754
755
    /**
756
     * Generates a JWT 'id_token' for OpenID Connect
757
     * @param Oauth2OidcUserInterface $user
758
     * @param string $clientIdentifier
759
     * @param CryptKey $privateKey
760
     * @param string[] $scopeIdentifiers
761
     * @param string|null $nonce
762
     * @param \DateTimeImmutable|null $expiryDateTime
763
     * @return \Lcobucci\JWT\Token\Plain
764
     * @throws InvalidConfigException
765
     * @see getOidcScopeCollection()
766
     */
767 2
    public function generateOpenIdConnectUserClaimsToken(
768
        $user,
769
        $clientIdentifier,
770
        $privateKey,
771
        $scopeIdentifiers,
772
        $nonce = null,
773
        $expiryDateTime = null
774
    ) {
775 2
        if (!($user instanceof Oauth2OidcUserInterface)) {
0 ignored issues
show
introduced by
$user is always a sub-type of rhertogh\Yii2Oauth2Serve...Oauth2OidcUserInterface.
Loading history...
776 1
            throw new InvalidConfigException('In order to support OpenID Connect '
777 1
                . get_class($user) . ' must implement ' . Oauth2OidcUserInterface::class);
778
        }
779
780 1
        $jwtConfiguration = Configuration::forAsymmetricSigner(
781 1
            new Sha256(),
782 1
            InMemory::plainText($privateKey->getKeyContents(), $privateKey->getPassPhrase() ?? ''),
783 1
            InMemory::empty(),
0 ignored issues
show
Deprecated Code introduced by
The function Lcobucci\JWT\Signer\Key\InMemory::empty() has been deprecated: Deprecated since v4.3 ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

783
            /** @scrutinizer ignore-deprecated */ InMemory::empty(),

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
784 1
        );
785
786 1
        $builder = $jwtConfiguration->builder()
787 1
            ->permittedFor($clientIdentifier)
788 1
            ->issuedBy(Yii::$app->request->hostInfo)
0 ignored issues
show
Bug introduced by
It seems like Yii::app->request->hostInfo can also be of type null; however, parameter $issuer of Lcobucci\JWT\Builder::issuedBy() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

788
            ->issuedBy(/** @scrutinizer ignore-type */ Yii::$app->request->hostInfo)
Loading history...
789 1
            ->issuedAt(new \DateTimeImmutable())
790 1
            ->relatedTo((string)$user->getIdentifier())
791 1
            ->withClaim(
792 1
                Oauth2OidcClaimInterface::OPENID_CONNECT_CLAIM_AUTH_TIME,
793 1
                $user->getLatestAuthenticatedAt()->getTimestamp()
794 1
            );
795
796 1
        if ($nonce) {
797 1
            $builder->withClaim(Oauth2OidcClaimInterface::OPENID_CONNECT_CLAIM_NONCE, $nonce);
798
        }
799
800 1
        if ($expiryDateTime) {
801 1
            $builder->expiresAt($expiryDateTime);
802
        }
803
804 1
        $oidcScopeCollection = $this->getOidcScopeCollection();
805
806 1
        $claims = $oidcScopeCollection->getFilteredClaims($scopeIdentifiers);
807
808 1
        foreach ($claims as $claim) {
809
            if (
810 1
                in_array(
811 1
                    $claim->getIdentifier(),
812 1
                    Oauth2OidcScopeInterface::OPENID_CONNECT_DEFAULT_SCOPE_CLAIMS[
813 1
                        Oauth2OidcScopeInterface::OPENID_CONNECT_SCOPE_OPENID
814 1
                    ]
815 1
                )
816
            ) {
817
                // Skip default claims for OpenID (already set above).
818 1
                continue;
819
            }
820 1
            $claimValue = $user->getOpenIdConnectClaimValue($claim, $this);
821 1
            $builder->withClaim($claim->getIdentifier(), $claimValue);
822
        }
823
824 1
        return $builder->getToken($jwtConfiguration->signer(), $jwtConfiguration->signingKey());
825
    }
826
}
827