altcha = new Altcha($this->hmacKey); } /** * @throws IOException * @throws FileNotFoundException */ public function provide(Operation $operation, array $uriVariables = [], array $context = []): IdCardRequest { if (!$operation instanceof Get) { throw new \RuntimeException('not supported', Response::HTTP_METHOD_NOT_ALLOWED); } $filters = $context['filters'] ?? []; $altchaPayload = $filters['payload'] ?? null; if ($altchaPayload === null) { throw new \RuntimeException('missing parameter: payload', Response::HTTP_BAD_REQUEST); } try { $valid = $this->altcha->verifySolution( urldecode($altchaPayload), true ); } catch (\Throwable) { $valid = false; } if (!$valid) { throw new \RuntimeException('Invalid payload'); } $photo = (new Path($this->projectDir)) ->append('static', 'profile.min.png') ->getContent(); $idCardRequest = new IdCardRequest(); $idCardRequest->setPhoto(base64_encode($photo)); $idCardRequest->setPlace($this->idPlace); $idCardRequest->setAge($this->idAge); $idCardRequest->setStatus($this->idStatus); return $idCardRequest; } }