예제 #1
0
 public function it_can_handle_errors_when_executing_a_request(RequestInterface $request)
 {
     $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)->willThrow(new \RuntimeException());
     $this->shouldThrow(ResponseException::class)->duringExecuteRequest($request);
 }
 public function it_allows_logged_in_user(ServerHttpRequest $httpRequest, RequestInterface $request, Token $token)
 {
     $tokenUuid = Uuid::uuid4();
     $passCode = bin2hex(random_bytes(20));
     $this->httpRequestParser->parseHttpRequest($httpRequest, [])->willReturn($request);
     $request->getRequestName()->willReturn($messageName = 'test.private');
     $httpRequest->getHeaderLine('Accept')->willReturn('*/*');
     $httpRequest->getHeaderLine('Authentication-Token')->willReturn($tokenUuid->toString());
     $httpRequest->getHeaderLine('Authentication-Pass-Code')->willReturn($passCode);
     $this->tokenService->getToken($tokenUuid, $passCode)->willReturn($token);
     $this->parseHttpRequest($httpRequest, [])->shouldReturn($request);
 }
예제 #3
0
 public function executeRequest(RequestInterface $request) : ResponseInterface
 {
     try {
         $token = $this->tokenService->getToken(Uuid::fromString($request['token']), $request['pass_code']);
         $this->tokenService->remove($token);
         return new Response(self::MESSAGE, [], $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 LogoutHandler.', new ServerErrorResponse([], $request));
     }
 }
예제 #4
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));
     }
 }
예제 #5
0
 private function isAllowed(RequestInterface $request, ServerHttpRequest $httpRequest)
 {
     if (in_array($request->getRequestName(), $this->publicMessageNames, true)) {
         return true;
     }
     try {
         $this->tokenService->getToken(Uuid::fromString($httpRequest->getHeaderLine('Authentication-Token')), $httpRequest->getHeaderLine('Authentication-Pass-Code'));
         return true;
     } catch (\Throwable $exception) {
         if (!$exception instanceof AuthException) {
             $this->log(LogLevel::ERROR, $exception->getMessage());
         }
         return false;
     }
 }
예제 #6
0
 public function logout(Token $token)
 {
     $this->tokenService->remove($token);
 }
 public function it_can_logout(Token $token)
 {
     $this->tokenService->remove($token)->shouldBeCalled();
     $this->logout($token);
 }