Skip to content

Commit 94af021

Browse files
committed
Add main auth code validation
1 parent f1e2af5 commit 94af021

File tree

3 files changed

+30
-17
lines changed

3 files changed

+30
-17
lines changed

src/Factories/CryptKeyFactory.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public function buildPrivateKey(): CryptKey
2222
return new CryptKey(
2323
$this->moduleConfig->getProtocolPrivateKeyPath(),
2424
$this->moduleConfig->getProtocolPrivateKeyPassPhrase(),
25-
false, // TODO mivanci Return to true
25+
true,
2626
);
2727
}
2828

src/Server/Grants/PreAuthCodeGrant.php

Lines changed: 29 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -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
/**

src/Services/OpMetadataService.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ private function initMetadata(): void
5050
$this->metadata[ClaimsEnum::EndSessionEndpoint->value] =
5151
$this->moduleConfig->getModuleUrl(RoutesEnum::EndSession->value);
5252
$this->metadata[ClaimsEnum::JwksUri->value] = $this->moduleConfig->getModuleUrl(RoutesEnum::Jwks->value);
53-
// TODO mivanci Resolve supported scopes from ScopeRepository (also include those from VCI).
5453
$this->metadata[ClaimsEnum::ScopesSupported->value] = array_keys($this->moduleConfig->getScopes());
5554
$this->metadata[ClaimsEnum::ResponseTypesSupported->value] = ['code', 'token', 'id_token', 'id_token token'];
5655
$this->metadata[ClaimsEnum::SubjectTypesSupported->value] = ['public'];

0 commit comments

Comments
 (0)