protected function signInWithLock(int $duration = null): Token
    {
        if ($this->store) {
            $factory = new Factory($this->store);
            $factory->setLogger($this->logger);
            $lock = $factory->createLock($this->user->getMpxUsername(), 10);

            // Blocking means this will throw an exception on failure.
            $lock->acquire(true);
        }

        try {
            // It's possible another thread has signed in for us, so check for a token first.
            $token = $this->tokenCachePool->getToken($this);
        } catch (TokenNotFoundException $e) {
            // We have the lock, and there's no token, so sign in.
            $token = $this->signIn($duration);
        }

        return $token;
    }