File tree Expand file tree Collapse file tree 4 files changed +34
-18
lines changed Expand file tree Collapse file tree 4 files changed +34
-18
lines changed Original file line number Diff line number Diff line change @@ -246,28 +246,28 @@ public function decode(
246
246
?string $ tokenNonce = null ,
247
247
?int $ tokenMaxAge = null ,
248
248
?int $ tokenLeeway = null ,
249
- ?int $ tokenNow = null
249
+ ?int $ tokenNow = null ,
250
+ ?int $ tokenType = null
250
251
): Token {
251
- // instantiate Token handler using the provided JWT, expecting an ID token, using the SDK configuration.
252
- $ token = new Token ($ this ->configuration , $ token , Token::TYPE_ID_TOKEN );
252
+ $ tokenType = $ tokenType ?? Token::TYPE_ID_TOKEN ;
253
+ $ tokenNonce = $ tokenNonce ?? $ this ->getTransientStore ()->getOnce ('nonce ' ) ?? null ;
254
+ $ tokenMaxAge = $ tokenMaxAge ?? $ this ->getTransientStore ()->getOnce ('max_age ' ) ?? null ;
255
+ $ tokenIssuer = null ;
253
256
254
- // Verify token signature.
257
+ $ token = new Token ( $ this -> configuration , $ token, $ tokenType );
255
258
$ token ->verify ();
256
259
257
- $ tokenMaxAge = $ tokenMaxAge ?? $ this ->getTransientStore ()->getOnce ('max_age ' ) ?? null ;
258
-
259
- // If pulling from transient storage, $tokenMaxAge might be a string.
260
+ // If pulled from transient storage, $tokenMaxAge might be a string.
260
261
if ($ tokenMaxAge !== null ) {
261
262
$ tokenMaxAge = (int ) $ tokenMaxAge ;
262
263
}
263
264
264
- // Validate token claims.
265
265
$ token ->validate (
266
- null ,
266
+ $ tokenIssuer ,
267
267
$ tokenAudience ,
268
268
$ tokenOrganization ,
269
- $ tokenNonce ?? $ this -> getTransientStore ()-> getOnce ( ' nonce ' ) ?? null ,
270
- $ tokenMaxAge ?? null ,
269
+ $ tokenNonce ,
270
+ $ tokenMaxAge ,
271
271
$ tokenLeeway ,
272
272
$ tokenNow
273
273
);
Original file line number Diff line number Diff line change @@ -139,11 +139,8 @@ public function validate(
139
139
$ tokenNonce = $ tokenNonce ?? null ;
140
140
$ tokenMaxAge = $ tokenMaxAge ?? $ this ->configuration ->getTokenMaxAge () ?? null ;
141
141
$ tokenLeeway = $ tokenLeeway ?? $ this ->configuration ->getTokenLeeway () ?? 60 ;
142
-
143
- // If 'aud' claim check isn't defined, fallback to client id, if configured.
144
- if (count ($ tokenAudience ) === 0 && $ this ->configuration ->hasClientId ()) {
145
- $ tokenAudience [] = (string ) $ this ->configuration ->getClientId ();
146
- }
142
+ $ tokenAudience [] = (string ) $ this ->configuration ->getClientId ();
143
+ $ tokenAudience = array_unique ($ tokenAudience );
147
144
148
145
$ validator = $ this ->parser ->validate ();
149
146
$ now = $ tokenNow ?? time ();
Original file line number Diff line number Diff line change @@ -391,6 +391,26 @@ public function defer(
391
391
$ auth0 ->decode ($ token );
392
392
})->throws (\Auth0 \SDK \Exception \InvalidTokenException::class);
393
393
394
+ test ('decode() can be used with access tokens ' , function (): void {
395
+ $ token = (new \Auth0 \Tests \Utilities \TokenGenerator ())->withHs256 ();
396
+
397
+ $ auth0 = new \Auth0 \SDK \Auth0 ($ this ->configuration + [
398
+ 'tokenAlgorithm ' => 'HS256 ' ,
399
+ ]);
400
+
401
+ $ decoded = $ auth0 ->decode ($ token ,
402
+ null ,
403
+ null ,
404
+ null ,
405
+ null ,
406
+ null ,
407
+ null ,
408
+ \Auth0 \SDK \Token::TYPE_TOKEN ,
409
+ );
410
+
411
+ expect ($ decoded ->getAudience ())->toContain ('__test_client_id__ ' );
412
+ });
413
+
394
414
test ('exchange() throws an exception if no code is present ' , function (): void {
395
415
$ auth0 = new \Auth0 \SDK \Auth0 ($ this ->configuration );
396
416
$ auth0 ->exchange ();
Original file line number Diff line number Diff line change @@ -158,12 +158,11 @@ function(): SdkConfiguration {
158
158
array $ claims
159
159
): void {
160
160
$ token = new Token ($ configuration , $ jwt ->token , Token::TYPE_ID_TOKEN );
161
-
162
161
$ token ->validate (null , [ $ claims ['aud ' ] ]);
163
162
})->with (['mocked data ' => [
164
163
function (): SdkConfiguration {
165
164
$ this ->configuration ->setDomain ('__test_domain__ ' );
166
- $ this ->configuration ->setClientId ('__test_client_id__ ' );
165
+ $ this ->configuration ->setClientId ('__diff_client_id__ ' );
167
166
$ this ->configuration ->setTokenAlgorithm ('HS256 ' );
168
167
return $ this ->configuration ;
169
168
},
You can’t perform that action at this time.
0 commit comments