@@ -529,69 +529,73 @@ private function parseMessage()
529
529
try {
530
530
$ this ->jwt = Jwt::getJwtClient ();
531
531
if (isset ($ this ->rawParameters ['id_token ' ])) {
532
- $ this ->jwt ->load ($ this ->rawParameters ['id_token ' ], $ this ->rsaKey );
532
+ $ this ->ok = $ this -> jwt ->load ($ this ->rawParameters ['id_token ' ], $ this ->rsaKey );
533
533
} else {
534
- $ this ->jwt ->load ($ this ->rawParameters ['JWT ' ], $ this ->rsaKey );
534
+ $ this ->ok = $ this -> jwt ->load ($ this ->rawParameters ['JWT ' ], $ this ->rsaKey );
535
535
}
536
- $ this ->ok = $ this ->jwt ->hasClaim ('iss ' ) && $ this ->jwt ->hasClaim ('aud ' ) &&
537
- $ this ->jwt ->hasClaim (Util::JWT_CLAIM_PREFIX . '/claim/deployment_id ' );
538
- if ($ this ->ok ) {
539
- $ iss = $ this ->jwt ->getClaim ('iss ' );
540
- $ aud = $ this ->jwt ->getClaim ('aud ' );
541
- $ deploymentId = $ this ->jwt ->getClaim (Util::JWT_CLAIM_PREFIX . '/claim/deployment_id ' );
542
- $ this ->ok = !empty ($ iss ) && !empty ($ aud ) && !empty ($ deploymentId );
543
- if (!$ this ->ok ) {
544
- $ this ->reason = 'iss, aud and/or deployment_id claim is empty ' ;
545
- } elseif (is_array ($ aud )) {
546
- if ($ this ->jwt ->hasClaim ('azp ' )) {
547
- $ this ->ok = !empty ($ this ->jwt ->getClaim ('azp ' ));
548
- if (!$ this ->ok ) {
549
- $ this ->reason = 'azp claim is empty ' ;
550
- } else {
551
- $ this ->ok = in_array ($ this ->jwt ->getClaim ('azp ' ), $ aud );
552
- if ($ this ->ok ) {
553
- $ aud = $ this ->jwt ->getClaim ('azp ' );
536
+ if (!$ this ->ok ) {
537
+ $ this ->reason = 'Message does not contain a valid JWT ' ;
538
+ } else {
539
+ $ this ->ok = $ this ->jwt ->hasClaim ('iss ' ) && $ this ->jwt ->hasClaim ('aud ' ) &&
540
+ $ this ->jwt ->hasClaim (Util::JWT_CLAIM_PREFIX . '/claim/deployment_id ' );
541
+ if ($ this ->ok ) {
542
+ $ iss = $ this ->jwt ->getClaim ('iss ' );
543
+ $ aud = $ this ->jwt ->getClaim ('aud ' );
544
+ $ deploymentId = $ this ->jwt ->getClaim (Util::JWT_CLAIM_PREFIX . '/claim/deployment_id ' );
545
+ $ this ->ok = !empty ($ iss ) && !empty ($ aud ) && !empty ($ deploymentId );
546
+ if (!$ this ->ok ) {
547
+ $ this ->reason = 'iss, aud and/or deployment_id claim is empty ' ;
548
+ } elseif (is_array ($ aud )) {
549
+ if ($ this ->jwt ->hasClaim ('azp ' )) {
550
+ $ this ->ok = !empty ($ this ->jwt ->getClaim ('azp ' ));
551
+ if (!$ this ->ok ) {
552
+ $ this ->reason = 'azp claim is empty ' ;
554
553
} else {
555
- $ this ->reason = 'azp claim value is not included in aud claim ' ;
554
+ $ this ->ok = in_array ($ this ->jwt ->getClaim ('azp ' ), $ aud );
555
+ if ($ this ->ok ) {
556
+ $ aud = $ this ->jwt ->getClaim ('azp ' );
557
+ } else {
558
+ $ this ->reason = 'azp claim value is not included in aud claim ' ;
559
+ }
560
+ }
561
+ } else {
562
+ $ aud = $ aud [0 ];
563
+ $ this ->ok = !empty ($ aud );
564
+ if (!$ this ->ok ) {
565
+ $ this ->reason = 'First element of aud claim is empty ' ;
556
566
}
557
567
}
558
- } else {
559
- $ aud = $ aud [0 ];
560
- $ this ->ok = !empty ($ aud );
568
+ } elseif ($ this ->jwt ->hasClaim ('azp ' )) {
569
+ $ this ->ok = $ this ->jwt ->getClaim ('azp ' ) === $ aud ;
561
570
if (!$ this ->ok ) {
562
- $ this ->reason = 'First element of aud claim is empty ' ;
571
+ $ this ->reason = 'aud claim does not match the azp claim ' ;
563
572
}
564
573
}
565
- } elseif ($ this ->jwt ->hasClaim ('azp ' )) {
566
- $ this ->ok = $ this ->jwt ->getClaim ('azp ' ) === $ aud ;
567
- if (!$ this ->ok ) {
568
- $ this ->reason = 'aud claim does not match the azp claim ' ;
569
- }
570
- }
571
- if ($ this ->ok ) {
572
- $ this ->platform = Platform::fromPlatformId ($ iss , $ aud , $ deploymentId , $ this ->dataConnector );
573
- if (isset ($ this ->rawParameters ['id_token ' ])) {
574
- $ this ->ok = !empty ($ this ->rawParameters ['state ' ]);
575
- if ($ this ->ok ) {
576
- $ nonce = new PlatformNonce ($ this ->platform , $ this ->rawParameters ['state ' ]);
577
- $ this ->ok = $ nonce ->load ();
574
+ if ($ this ->ok ) {
575
+ $ this ->platform = Platform::fromPlatformId ($ iss , $ aud , $ deploymentId , $ this ->dataConnector );
576
+ if (isset ($ this ->rawParameters ['id_token ' ])) {
577
+ $ this ->ok = !empty ($ this ->rawParameters ['state ' ]);
578
578
if ($ this ->ok ) {
579
- $ this ->ok = $ nonce ->delete ();
579
+ $ nonce = new PlatformNonce ($ this ->platform , $ this ->rawParameters ['state ' ]);
580
+ $ this ->ok = $ nonce ->load ();
581
+ if ($ this ->ok ) {
582
+ $ this ->ok = $ nonce ->delete ();
583
+ }
580
584
}
581
585
}
586
+ if ($ this ->ok ) {
587
+ $ this ->platform ->platformId = $ this ->jwt ->getClaim ('iss ' );
588
+ $ this ->messageParameters = array ();
589
+ $ this ->messageParameters ['oauth_consumer_key ' ] = $ aud ;
590
+ $ this ->messageParameters ['oauth_signature_method ' ] = $ this ->jwt ->getHeader ('alg ' );
591
+ $ this ->parseClaims ();
592
+ } else {
593
+ $ this ->reason = 'state parameter is invalid or missing ' ;
594
+ }
582
595
}
583
- if ($ this ->ok ) {
584
- $ this ->platform ->platformId = $ this ->jwt ->getClaim ('iss ' );
585
- $ this ->messageParameters = array ();
586
- $ this ->messageParameters ['oauth_consumer_key ' ] = $ aud ;
587
- $ this ->messageParameters ['oauth_signature_method ' ] = $ this ->jwt ->getHeader ('alg ' );
588
- $ this ->parseClaims ();
589
- } else {
590
- $ this ->reason = 'state parameter is invalid or missing ' ;
591
- }
596
+ } else {
597
+ $ this ->reason = 'iss, aud and/or deployment_id claim not found ' ;
592
598
}
593
- } else {
594
- $ this ->reason = 'iss, aud and/or deployment_id claim not found ' ;
595
599
}
596
600
} catch (\Exception $ e ) {
597
601
$ this ->ok = false ;
0 commit comments