@@ -717,15 +717,39 @@ private function verifyJWTclaims($claims, $accessToken = null)
717
717
$ bit = '256 ' ;
718
718
}
719
719
$ len = ((int )$ bit )/16 ;
720
- $ expecte_at_hash = $ this ->urlEncode (substr (hash ('sha ' .$ bit , $ accessToken , true ), 0 , $ len ));
720
+ $ expected_at_hash = $ this ->urlEncode (substr (hash ('sha ' .$ bit , $ accessToken , true ), 0 , $ len ));
721
721
}
722
- return (($ claims ->iss == $ this ->getProviderURL ())
723
- && (($ claims ->aud == $ this ->clientID ) || (in_array ($ this ->clientID , $ claims ->aud )))
724
- && ($ claims ->nonce == $ this ->getNonce ())
725
- && (!isset ($ claims ->exp ) || $ claims ->exp >= time ())
726
- && (!isset ($ claims ->nbf ) || $ claims ->nbf <= time ())
727
- && (!isset ($ claims ->at_hash ) || $ claims ->at_hash == $ expecte_at_hash )
728
- );
722
+
723
+ if ($ claims ->iss !== $ this ->getProviderURL ()) {
724
+ throw new Exception ('iss does not match getProviderURL: ' .$ claims ->iss .' !== ' .$ this ->getProviderURL ());
725
+ }
726
+
727
+ if ($ claims ->aud !== $ this ->clientID ) {
728
+ if (!in_array ($ this ->clientID , $ claims ->aud )) {
729
+ throw new Exception ('aud does not match clientID: ' .json_encode ($ claims ->aud ).' <> ' .$ this ->clientID );
730
+ }
731
+ }
732
+
733
+ if ($ claims ->nonce !== $ this ->getNonce ()) {
734
+ throw new Exception ('nonce does not match getNonce: ' .$ claims ->nonce .' !== ' .$ this ->getNonce ());
735
+ }
736
+ if (isset ($ claims ->exp )) {
737
+ if ($ claims ->exp <= time ()) {
738
+ throw new Exception ('exp already: ' .$ claims ->exp .' <= ' .time ());
739
+ }
740
+ }
741
+ if (isset ($ claims ->nbf )) {
742
+ if ($ claims ->nbf >= time ()) {
743
+ throw new Exception ('nbf not yet: ' .$ claims ->nbf .' >= ' .time ());
744
+ }
745
+ }
746
+ if (isset ($ claims ->at_hash )) {
747
+ if ($ claims ->at_hash !== $ expected_at_hash ) {
748
+ throw new Exception ('at_hash does not match expected_at_hash: ' .$ claims ->at_hash .' !== ' .$ expected_at_hash );
749
+ }
750
+ }
751
+
752
+ return true ;
729
753
}
730
754
731
755
/**
@@ -1173,7 +1197,7 @@ protected function setNonce($nonce)
1173
1197
*/
1174
1198
protected function getNonce ()
1175
1199
{
1176
- static ::getSession ('openid_connect_nonce ' );
1200
+ return static ::getSession ('openid_connect_nonce ' );
1177
1201
}
1178
1202
1179
1203
/**
0 commit comments