users = $users; $this->bus = $bus; $this->events = $events; } /** * {@inheritdoc} */ public function handle(ServerRequestInterface $request): ResponseInterface { $body = $request->getParsedBody(); $identification = Arr::get($body, 'identification'); $password = Arr::get($body, 'password'); $lifetime = Arr::get($body, 'lifetime', 3600); $user = $this->users->findByIdentification($identification); if (! $user || ! $user->checkPassword($password)) { throw new NotAuthenticatedException; } $token = AccessToken::generate($user->id, $lifetime); $token->save(); return new JsonResponse([ 'token' => $token->token, 'userId' => $user->id ]); } }