|
10 | 10 | use SimpleSAML\Module\oidc\Entities\AccessTokenEntity; |
11 | 11 | use SimpleSAML\Module\oidc\ModuleConfig; |
12 | 12 | use SimpleSAML\Module\oidc\Repositories\AccessTokenRepository; |
| 13 | +use SimpleSAML\Module\oidc\Repositories\IssuerStateRepository; |
13 | 14 | use SimpleSAML\Module\oidc\Repositories\UserRepository; |
14 | 15 | use SimpleSAML\Module\oidc\Server\Exceptions\OidcServerException; |
15 | 16 | use SimpleSAML\Module\oidc\Services\LoggerService; |
@@ -53,6 +54,7 @@ public function __construct( |
53 | 54 | protected readonly RequestParamsResolver $requestParamsResolver, |
54 | 55 | protected readonly UserRepository $userRepository, |
55 | 56 | protected readonly Did $did, |
| 57 | + protected readonly IssuerStateRepository $issuerStateRepository, |
56 | 58 | ) { |
57 | 59 | if (!$this->moduleConfig->getVerifiableCredentialEnabled()) { |
58 | 60 | $this->loggerService->warning('Verifiable Credential capabilities not enabled.'); |
@@ -121,6 +123,30 @@ public function credential(Request $request): Response |
121 | 123 | ); |
122 | 124 | } |
123 | 125 |
|
| 126 | + $issuerState = $accessToken->getIssuerState(); |
| 127 | + if (!is_string($issuerState)) { |
| 128 | + $this->loggerService->error( |
| 129 | + 'CredentialIssuerCredentialController::credential: Issuer state missing in access token.', |
| 130 | + ['access_token' => $accessToken], |
| 131 | + ); |
| 132 | + return $this->routes->newJsonErrorResponse( |
| 133 | + 'invalid_token', |
| 134 | + 'Issuer state missing in access token.', |
| 135 | + 401, |
| 136 | + ); |
| 137 | + } |
| 138 | + |
| 139 | + if ($this->issuerStateRepository->findValid($issuerState) === null) { |
| 140 | + $this->loggerService->warning( |
| 141 | + 'CredentialIssuerCredentialController::credential: Issuer state not valid.', |
| 142 | + ['issuer_state' => $issuerState], |
| 143 | + ); |
| 144 | + return $this->routes->newJsonErrorResponse( |
| 145 | + 'invalid_token', |
| 146 | + 'Issuer state not valid.', |
| 147 | + ); |
| 148 | + } |
| 149 | + |
124 | 150 | if ( |
125 | 151 | isset($requestData[ClaimsEnum::CredentialConfigurationId->value]) && |
126 | 152 | isset($requestData[ClaimsEnum::CredentialIdentifier->value]) |
@@ -652,7 +678,11 @@ public function credential(Request $request): Response |
652 | 678 | throw new OpenIdException('Invalid credential format ID.'); |
653 | 679 | } |
654 | 680 |
|
655 | | - $this->loggerService->debug('response', [ |
| 681 | + $this->loggerService->debug('Revoking issuer state.', ['issuerState' => $issuerState]); |
| 682 | + ; |
| 683 | + $this->issuerStateRepository->revoke($issuerState); |
| 684 | + |
| 685 | + $this->loggerService->debug('Returning credential response.', [ |
656 | 686 | 'credentials' => [ |
657 | 687 | ['credential' => $verifiableCredential->getToken()], |
658 | 688 | ], |
|
0 commit comments