Exemple #1
0
 public function executeRequest(RequestInterface $request) : ResponseInterface
 {
     try {
         $token = $this->tokenService->getToken(Uuid::fromString($request['token']), $request['pass_code']);
         $newToken = $this->tokenService->refresh($token);
         return new Response(self::MESSAGE, ['token' => $newToken->getUuid()->toString(), 'pass_code' => $newToken->getPassCode(), 'expires' => $newToken->getExpires()->format('Y-m-d H:i:s')], $request);
     } catch (AuthException $exception) {
         return new Response($exception->getMessage(), [], $request);
     } catch (\Throwable $exception) {
         $this->log(LogLevel::ERROR, $exception->getMessage());
         throw new ResponseException('An error occurred during RefreshTokenHandler.', new ServerErrorResponse([], $request));
     }
 }
 public function it_can_execute_a_request(RequestInterface $request, Token $oldToken, Token $newToken)
 {
     $tokenUuid = Uuid::uuid4()->toString();
     $passCode = bin2hex(random_bytes(20));
     $request->getAcceptContentType()->willReturn('*/*');
     $request->offsetGet('token')->willReturn($tokenUuid);
     $request->offsetGet('pass_code')->willReturn($passCode);
     $this->tokenService->getToken(Uuid::fromString($tokenUuid), $passCode)->willReturn($oldToken);
     $this->tokenService->refresh($oldToken)->willReturn($newToken);
     $newUuid = Uuid::uuid4();
     $newPassCode = bin2hex(random_bytes(20));
     $expires = new \DateTimeImmutable('+42 seconds');
     $newToken->getUuid()->willReturn($newUuid);
     $newToken->getPassCode()->willReturn($newPassCode);
     $newToken->getExpires()->willReturn($expires);
     $response = $this->executeRequest($request);
     $response->shouldHaveType(ResponseInterface::class);
     $response->getResponseName()->shouldReturn(RefreshTokenHandler::MESSAGE);
     $response['token']->shouldBe($newUuid->toString());
     $response['pass_code']->shouldBe($newPassCode);
     $response['expires']->shouldBe($expires->format('Y-m-d H:i:s'));
 }