public function login(ServerRequestInterface $request, ?Adapter $adapter = null): bool
    {
        $started = $this->session->resume() || $this->session->start();
        if (!$started) {
            return false;
        }

        $login = $adapter ?? $this->adapter;
        if ($login === null) {
            throw new \InvalidArgumentException('You must specify an adapter for authentication');
        }
        $this->principal = $principal = $login->login($request);

        $this->session->clear();
        $this->session->regenerateId();

        $this->values->offsetSet('principal', $principal);
        $now = microtime(true);
        $this->values->offsetSet('firstActive', $now);
        $this->values->offsetSet('lastActive', $now);

        $this->logger->info(
            "Authentication login: {user}",
            ['user' => $principal]
        );
        return $this->publishLogin($principal);
    }