appManager->getEnabledAppsForUser($user); $providers = []; foreach ($allApps as $appId) { $info = $this->appManager->getAppInfo($appId); if (isset($info['two-factor-providers'])) { /** @var string[] $providerClasses */ $providerClasses = $info['two-factor-providers']; foreach ($providerClasses as $class) { try { $this->loadTwoFactorApp($appId); $provider = \OCP\Server::get($class); $providers[$provider->getId()] = $provider; } catch (QueryException $exc) { // Provider class can not be resolved throw new Exception("Could not load two-factor auth provider $class"); } } } } $registeredProviders = $this->coordinator->getRegistrationContext()?->getTwoFactorProviders() ?? []; foreach ($registeredProviders as $provider) { try { $this->loadTwoFactorApp($provider->getAppId()); $providerInstance = \OCP\Server::get($provider->getService()); $providers[$providerInstance->getId()] = $providerInstance; } catch (QueryException $exc) { // Provider class can not be resolved throw new Exception('Could not load two-factor auth provider ' . $provider->getService()); } } return $providers; } /** * Load an app by ID if it has not been loaded yet */ protected function loadTwoFactorApp(string $appId): void { if (!$this->appManager->isAppLoaded($appId)) { $this->appManager->loadApp($appId); } } }