|
19 | 19 | use OCP\App\AppPathNotFoundException; |
20 | 20 | use OCP\App\IAppManager; |
21 | 21 | use OCP\Authentication\IAlternativeLogin; |
| 22 | +use OCP\Authentication\IAlternativeLoginProvider; |
22 | 23 | use OCP\BackgroundJob\IJobList; |
23 | 24 | use OCP\EventDispatcher\IEventDispatcher; |
24 | 25 | use OCP\IAppConfig; |
|
41 | 42 | * upgrading and removing apps. |
42 | 43 | */ |
43 | 44 | class OC_App { |
| 45 | + |
| 46 | + /** @var list<array{name: string, href: string, class: string}> */ |
44 | 47 | private static array $altLogin = []; |
45 | 48 | private static array $alreadyRegistered = []; |
46 | 49 | public const supportedApp = 300; |
@@ -272,12 +275,55 @@ public static function registerLogIn(array $entry): void { |
272 | 275 | } |
273 | 276 |
|
274 | 277 | /** |
275 | | - * @return array |
| 278 | + * @return list<array{name: string, href: string, class: string}> |
276 | 279 | */ |
277 | 280 | public static function getAlternativeLogIns(): array { |
278 | 281 | /** @var Coordinator $bootstrapCoordinator */ |
279 | 282 | $bootstrapCoordinator = Server::get(Coordinator::class); |
280 | 283 |
|
| 284 | + foreach ($bootstrapCoordinator->getRegistrationContext()->getAlternativeLoginProviders() as $registration) { |
| 285 | + if (!in_array(IAlternativeLoginProvider::class, class_implements($registration->getService()), true)) { |
| 286 | + Server::get(LoggerInterface::class)->error('Alternative login option {option} does not implement {interface} and is therefore ignored.', [ |
| 287 | + 'option' => $registration->getService(), |
| 288 | + 'interface' => IAlternativeLoginProvider::class, |
| 289 | + 'app' => $registration->getAppId(), |
| 290 | + ]); |
| 291 | + continue; |
| 292 | + } |
| 293 | + |
| 294 | + try { |
| 295 | + /** @var IAlternativeLoginProvider $provider */ |
| 296 | + $provider = Server::get($registration->getService()); |
| 297 | + } catch (ContainerExceptionInterface $e) { |
| 298 | + Server::get(LoggerInterface::class)->error('Alternative login option {option} can not be initialized.', |
| 299 | + [ |
| 300 | + 'exception' => $e, |
| 301 | + 'option' => $registration->getService(), |
| 302 | + 'app' => $registration->getAppId(), |
| 303 | + ]); |
| 304 | + continue; |
| 305 | + } |
| 306 | + |
| 307 | + foreach ($provider->getAlternativeLogins() as $alternativeLogin) { |
| 308 | + try { |
| 309 | + $alternativeLogin->load(); |
| 310 | + |
| 311 | + self::$altLogin[] = [ |
| 312 | + 'name' => $alternativeLogin->getLabel(), |
| 313 | + 'href' => $alternativeLogin->getLink(), |
| 314 | + 'class' => $alternativeLogin->getClass(), |
| 315 | + ]; |
| 316 | + } catch (Throwable $e) { |
| 317 | + Server::get(LoggerInterface::class)->error('Alternative login option {option} had an error while loading.', |
| 318 | + [ |
| 319 | + 'exception' => $e, |
| 320 | + 'option' => $registration->getService(), |
| 321 | + 'app' => $registration->getAppId(), |
| 322 | + ]); |
| 323 | + } |
| 324 | + } |
| 325 | + } |
| 326 | + |
281 | 327 | foreach ($bootstrapCoordinator->getRegistrationContext()->getAlternativeLogins() as $registration) { |
282 | 328 | if (!in_array(IAlternativeLogin::class, class_implements($registration->getService()), true)) { |
283 | 329 | Server::get(LoggerInterface::class)->error('Alternative login option {option} does not implement {interface} and is therefore ignored.', [ |
|
0 commit comments