public function createDelegatorWithName(ServiceLocatorInterface $serviceLocator, $name, $requestedName, $callback)
    {
        /** @var OAuth2Server|callable $oauth2Server */
        $oauth2Server = $callback();

        /* ensure compatibility with https://github.com/zfcampus/zf-oauth2/pull/93 */
        if (is_callable($oauth2Server)) {
            $oauth2ServerFactory = $oauth2Server;
            $oauth2Server        = $oauth2ServerFactory();
        }

        /** @var ModuleOptions $moduleOptions */
        $moduleOptions = $serviceLocator->get(ModuleOptions::class);

        $thirdPartyProviders = $moduleOptions->getThirdPartyProviders();

        if ($moduleOptions->isThirdPartyGrantTypeEnabled() && ! empty($thirdPartyProviders)) {
            /** @var ThirdPartyGrantType $thirdPartyGrant */
            $thirdPartyGrant = $serviceLocator->get(ThirdPartyGrantType::class);

            $oauth2Server->addGrantType($thirdPartyGrant);
        }

        return isset($oauth2ServerFactory) ? $oauth2ServerFactory : $oauth2Server;
    }