@@ -142,22 +142,9 @@ public function respondToAccessTokenRequest(
142142 throw OidcServerException::invalidGrant ('Invalid pre-authorized code. ' );
143143 }
144144
145- if (!$ preAuthorizedCode ->isVciPreAuthorized ()) {
146- $ this ->loggerService ->error (
147- 'Pre-authorized code is not pre-authorized. Value was: ' . $ preAuthorizedCodeId ,
148- );
149- throw OidcServerException::invalidGrant ('Pre-authorized code is not pre-authorized. ' );
150- }
151-
152- if ($ preAuthorizedCode ->isRevoked ()) {
153- $ this ->loggerService ->error ('Pre-authorized code is revoked. Value was: ' . $ preAuthorizedCodeId );
154- throw OidcServerException::invalidGrant ('Pre-authorized code is revoked. ' );
155- }
156-
157145 $ client = $ preAuthorizedCode ->getClient ();
158146
159- // TODO validate code
160- // $this->validateAuthorizationCode($preAuthorizedCode, $client, $request);
147+ $ this ->validateAuthorizationCode ($ preAuthorizedCode , $ client , $ request , $ preAuthorizedCode );
161148
162149 // Validate Transaction Code.
163150 if (($ preAuthorizedCodeTxCode = $ preAuthorizedCode ->getTxCode ()) !== null ) {
@@ -200,7 +187,6 @@ public function respondToAccessTokenRequest(
200187 /** @var ?array $authorizationDetails */
201188 $ authorizationDetails = $ resultBag ->get (AuthorizationDetailsRule::class)?->getValue();
202189
203- // TODO mivanci add flow, authorization details, bound client_id and redirect_uri to access token.
204190 // Issue and persist new access token
205191 $ accessToken = $ this ->issueAccessToken (
206192 $ accessTokenTTL ,
@@ -238,6 +224,34 @@ protected function validateAuthorizationCode(
238224 ServerRequestInterface $ request ,
239225 AuthCodeEntity $ storedAuthCodeEntity ,
240226 ): void {
227+ $ this ->loggerService ->debug ('PreAuthCodeGrant::validateAuthorizationCode ' );
228+
229+ if (!$ storedAuthCodeEntity ->isVciPreAuthorized ()) {
230+ $ this ->loggerService ->error (
231+ 'Pre-authorized code is not pre-authorized. ID was: ' ,
232+ ['preAuthCodeId ' => $ storedAuthCodeEntity ->getIdentifier ()],
233+ );
234+ throw OidcServerException::invalidGrant ('Pre-authorized code is not pre-authorized. ' );
235+ }
236+
237+ if ($ storedAuthCodeEntity ->getExpiryDateTime ()->getTimestamp () < time ()) {
238+ $ this ->loggerService ->error (
239+ 'Pre-authorized code is expired. ID was: ' ,
240+ ['preAuthCodeId ' => $ storedAuthCodeEntity ->getIdentifier ()],
241+ );
242+
243+ throw OidcServerException::invalidGrant ('Pre-authorized code is expired. ' );
244+ }
245+
246+ if ($ storedAuthCodeEntity ->isRevoked ()) {
247+ $ this ->loggerService ->error (
248+ 'Pre-authorized code is revoked. ID was: ' ,
249+ ['preAuthCodeId ' => $ storedAuthCodeEntity ->getIdentifier ()],
250+ );
251+ throw OidcServerException::invalidGrant ('Pre-authorized code is revoked. ' );
252+ }
253+
254+ $ this ->loggerService ->debug ('PreAuthCodeGrant::validateAuthorizationCode passed. ' );
241255 }
242256
243257 /**
0 commit comments