@@ -204,6 +204,8 @@ public function __construct(
204204 */
205205 public function canRespondToAuthorizationRequest (ServerRequestInterface $ request ): bool
206206 {
207+ $ this ->loggerService ->debug ('AuthCodeGrant::canRespondToAuthorizationRequest ' );
208+
207209 $ requestParams = $ this ->requestParamsResolver ->getAllBasedOnAllowedMethods (
208210 $ request ,
209211 $ this ->allowedAuthorizationHttpMethods ,
@@ -732,6 +734,8 @@ public function validateAuthorizationRequestWithRequestRules(
732734 ServerRequestInterface $ request ,
733735 ResultBagInterface $ resultBag ,
734736 ): OAuth2AuthorizationRequest {
737+ $ this ->loggerService ->debug ('AuthCodeGrant::validateAuthorizationRequestWithRequestRules ' );
738+
735739 $ rulesToExecute = [
736740 ClientIdRule::class,
737741 RequestObjectRule::class,
@@ -758,6 +762,12 @@ public function validateAuthorizationRequestWithRequestRules(
758762 /** @var \SimpleSAML\Module\oidc\Entities\Interfaces\ClientEntityInterface $client */
759763 $ client = $ resultBag ->getOrFail (ClientRule::class)->getValue ();
760764
765+ $ this ->loggerService ->debug ('AuthCodeGrant: Resolved data: ' , [
766+ 'redirectUri ' => $ redirectUri ,
767+ 'state ' => $ state ,
768+ 'clientId ' => $ client ->getIdentifier (),
769+ ]);
770+
761771 // Some rules have to have certain things available in order to work properly...
762772 $ this ->requestRulesManager ->setData ('default_scope ' , $ this ->defaultScope );
763773 $ this ->requestRulesManager ->setData ('scope_delimiter_string ' , self ::SCOPE_DELIMITER_STRING );
@@ -769,9 +779,13 @@ public function validateAuthorizationRequestWithRequestRules(
769779 $ this ->allowedAuthorizationHttpMethods ,
770780 );
771781
782+ $ this ->loggerService ->debug ('AuthCodeGrant: executed rules. ' , ['rulesToExecute ' => $ rulesToExecute ]);
783+
772784 /** @var \League\OAuth2\Server\Entities\ScopeEntityInterface[] $scopes */
773785 $ scopes = $ resultBag ->getOrFail (ScopeRule::class)->getValue ();
774786
787+ $ this ->loggerService ->debug ('AuthCodeGrant: Resolved scopes: ' , ['scopes ' => $ scopes ]);
788+
775789 $ oAuth2AuthorizationRequest = new OAuth2AuthorizationRequest ();
776790
777791 $ oAuth2AuthorizationRequest ->setClient ($ client );
@@ -786,42 +800,66 @@ public function validateAuthorizationRequestWithRequestRules(
786800 /** @var ?string $codeChallenge */
787801 $ codeChallenge = $ resultBag ->getOrFail (CodeChallengeRule::class)->getValue ();
788802 if ($ codeChallenge ) {
803+ $ this ->loggerService ->debug ('AuthCodeGrant: Code challenge: ' , [
804+ 'codeChallenge ' => $ codeChallenge ,
805+ ]);
789806 /** @var string $codeChallengeMethod */
790807 $ codeChallengeMethod = $ resultBag ->getOrFail (CodeChallengeMethodRule::class)->getValue ();
791808
792809 $ oAuth2AuthorizationRequest ->setCodeChallenge ($ codeChallenge );
793810 $ oAuth2AuthorizationRequest ->setCodeChallengeMethod ($ codeChallengeMethod );
811+ } else {
812+ $ this ->loggerService ->debug ('AuthCodeGrant: No code challenge present. ' );
794813 }
795814
815+ $ isOidcCandidate = $ this ->isOidcCandidate ($ oAuth2AuthorizationRequest );
816+
817+
818+
819+ $ this ->loggerService ->debug ('AuthCodeGrant: Is OIDC candidate: ' , [
820+ 'isOidcCandidate ' => $ isOidcCandidate ,
821+ ]);
822+
796823 $ isVciAuthorizationCodeRequest = $ this ->requestParamsResolver ->isVciAuthorizationCodeRequest (
797824 $ request ,
798825 $ this ->allowedAuthorizationHttpMethods ,
799826 );
800827
828+ $ this ->loggerService ->debug ('AuthCodeGrant: Is VCI authorization code request: ' , [
829+ 'isVciAuthorizationCodeRequest ' => $ isVciAuthorizationCodeRequest ,
830+ ]);
831+
832+
801833 if (
802- (! $ this -> isOidcCandidate ( $ oAuth2AuthorizationRequest ) ) &&
834+ (! $ isOidcCandidate ) &&
803835 (! $ isVciAuthorizationCodeRequest )
804836 ) {
837+ $ this ->loggerService ->debug ('Not an OIDC nor VCI request, returning as OAuth2 request. ' );
805838 return $ oAuth2AuthorizationRequest ;
806839 }
807840
841+ $ this ->loggerService ->debug ('AuthCodeGrant: OIDC or VCI request, continuing with request setup. ' );
842+
808843 $ authorizationRequest = AuthorizationRequest::fromOAuth2AuthorizationRequest ($ oAuth2AuthorizationRequest );
809844
810845 $ nonce = $ this ->requestParamsResolver ->getAsStringBasedOnAllowedMethods (
811846 ParamsEnum::Nonce->value ,
812847 $ request ,
813848 $ this ->allowedAuthorizationHttpMethods ,
814849 );
850+ $ this ->loggerService ->debug ('AuthCodeGrant: Nonce: ' , ['nonce ' => $ nonce ]);
815851 if ($ nonce !== null ) {
816852 $ authorizationRequest ->setNonce ($ nonce );
817853 }
818854
819855 $ maxAge = $ resultBag ->get (MaxAgeRule::class);
856+ $ this ->loggerService ->debug ('AuthCodeGrant: MaxAge: ' , ['maxAge ' => $ maxAge ]);
820857 if (null !== $ maxAge ) {
821858 $ authorizationRequest ->setAuthTime ((int ) $ maxAge ->getValue ());
822859 }
823860
824861 $ requestClaims = $ resultBag ->get (RequestedClaimsRule::class);
862+ $ this ->loggerService ->debug ('AuthCodeGrant: Requested claims: ' , ['requestClaims ' => $ requestClaims ]);
825863 if (null !== $ requestClaims ) {
826864 /** @var ?array $requestClaimValues */
827865 $ requestClaimValues = $ requestClaims ->getValue ();
@@ -832,35 +870,54 @@ public function validateAuthorizationRequestWithRequestRules(
832870
833871 /** @var array|null $acrValues */
834872 $ acrValues = $ resultBag ->getOrFail (AcrValuesRule::class)->getValue ();
873+ $ this ->loggerService ->debug ('AuthCodeGrant: ACR values: ' , ['acrValues ' => $ acrValues ]);
835874 $ authorizationRequest ->setRequestedAcrValues ($ acrValues );
836875
837876
838877 $ authorizationRequest ->setIsVciRequest ($ isVciAuthorizationCodeRequest );
839- $ authorizationRequest ->setFlowType (
840- $ isVciAuthorizationCodeRequest ?
841- FlowTypeEnum::VciAuthorizationCode :
842- FlowTypeEnum::OidcAuthorizationCode,
843- );
878+ $ flowType = $ isVciAuthorizationCodeRequest ?
879+ FlowTypeEnum::VciAuthorizationCode : FlowTypeEnum::OidcAuthorizationCode;
880+ $ this ->loggerService ->debug ('AuthCodeGrant: FlowType: ' , ['flowType ' => $ flowType ]);
881+ $ authorizationRequest ->setFlowType ($ flowType );
844882
845883 /** @var ?string $issuerState */
846884 $ issuerState = $ resultBag ->get (IssuerStateRule::class)?->getValue();
885+ $ this ->loggerService ->debug ('AuthCodeGrant: Issuer state: ' , ['issuerState ' => $ issuerState ]);
847886 $ authorizationRequest ->setIssuerState ($ issuerState );
848887
849888 /** @var ?array $authorizationDetails */
850889 $ authorizationDetails = $ resultBag ->get (AuthorizationDetailsRule::class)?->getValue();
890+ $ this ->loggerService ->debug (
891+ 'AuthCodeGrant: Authorization details: ' ,
892+ ['authorizationDetails ' => $ authorizationDetails ],
893+ );
851894 $ authorizationRequest ->setAuthorizationDetails ($ authorizationDetails );
852895
853896 // Check if we are using a generic client for this request. This can happen for non-registered clients
854897 // in VCI flows. This can be removed once the VCI clients (wallets) are properly registered using DCR.
855898 if ($ client ->isGeneric ()) {
899+ $ this ->loggerService ->debug (
900+ 'AuthCodeGrant: Generic client is used for authorization request. ' ,
901+ ['genericClientId ' => $ client ->getIdentifier ()],
902+ );
856903 // The generic client was used. Make sure to store actually used client_id and redirect_uri params.
857- /** @var string $clientId */
858- $ clientId = $ resultBag ->getOrFail (ClientIdRule::class)->getValue ();
859- $ authorizationRequest ->setBoundClientId ($ clientId );
904+ /** @var string $clientIdParam */
905+ $ clientIdParam = $ resultBag ->getOrFail (ClientIdRule::class)->getValue ();
906+ $ this ->loggerService ->debug (
907+ 'AuthCodeGrant: Binding client_id param to request: ' ,
908+ ['clientIdParam ' => $ clientIdParam ],
909+ );
910+ $ authorizationRequest ->setBoundClientId ($ clientIdParam );
860911
912+ $ this ->loggerService ->debug (
913+ 'AuthCodeGrant: Binding redirect_uri param to request: ' ,
914+ ['redirectUri ' => $ redirectUri ],
915+ );
861916 $ authorizationRequest ->setBoundRedirectUri ($ redirectUri );
862917 }
863918
919+ $ this ->loggerService ->debug ('AuthCodeGrant: Finished setting up authorization request. ' );
920+
864921 return $ authorizationRequest ;
865922 }
866923
0 commit comments