1111use Exception ;
1212use OC_App ;
1313use OCA \Files \Event \LoadAdditionalScriptsEvent ;
14+ use OCA \UserOIDC \AlternativeLogin \AlternativeLoginProvider ;
1415use OCA \UserOIDC \Db \ProviderMapper ;
1516use OCA \UserOIDC \Event \ExchangedTokenRequestedEvent ;
1617use OCA \UserOIDC \Event \ExternalTokenRequestedEvent ;
@@ -70,6 +71,14 @@ public function register(IRegistrationContext $context): void {
7071 if (class_exists (\OCP \Authentication \Events \TokenInvalidatedEvent::class)) {
7172 $ context ->registerEventListener (\OCP \Authentication \Events \TokenInvalidatedEvent::class, TokenInvalidatedListener::class);
7273 }
74+
75+ if (version_compare ($ config ->getSystemValueString ('version ' , '0.0.0 ' ), '34.0.0 ' , '>= ' )) {
76+ /**
77+ * @psalm-suppress UndefinedInterfaceMethod
78+ * @psalm-suppress MissingDependency
79+ */
80+ $ context ->registerAlternativeLoginProvider (AlternativeLoginProvider::class);
81+ }
7382 }
7483
7584 public function boot (IBootContext $ context ): void {
@@ -83,7 +92,9 @@ public function boot(IBootContext $context): void {
8392
8493 try {
8594 $ context ->injectFn (\Closure::fromCallable ([$ this , 'registerRedirect ' ]));
86- $ context ->injectFn (\Closure::fromCallable ([$ this , 'registerLogin ' ]));
95+ if (version_compare ($ this ->getContainer ()->get (IConfig::class)->getSystemValueString ('version ' , '0.0.0 ' ), '34.0.0 ' , '< ' )) {
96+ $ context ->injectFn (\Closure::fromCallable ([$ this , 'registerLogin ' ]));
97+ }
8798 } catch (Throwable $ e ) {
8899 }
89100 }
@@ -93,7 +104,6 @@ private function checkLoginToken(TokenService $tokenService): void {
93104 }
94105
95106 private function registerRedirect (IRequest $ request , IURLGenerator $ urlGenerator , SettingsService $ settings , ProviderMapper $ providerMapper ): void {
96- $ providers = $ this ->getCachedProviders ($ providerMapper );
97107 $ redirectUrl = $ request ->getParam ('redirect_url ' );
98108 $ absoluteRedirectUrl = !empty ($ redirectUrl ) ? $ urlGenerator ->getAbsoluteURL ($ redirectUrl ) : $ redirectUrl ;
99109
@@ -104,13 +114,16 @@ private function registerRedirect(IRequest $request, IURLGenerator $urlGenerator
104114 } catch (Exception $ e ) {
105115 // in case any errors happen when checking for the path do not apply redirect logic as it is only needed for the login
106116 }
107- if ($ isDefaultLogin && !$ settings ->getAllowMultipleUserBackEnds () && count ($ providers ) === 1 ) {
108- $ targetUrl = $ urlGenerator ->linkToRoute (self ::APP_ID . '.login.login ' , [
109- 'providerId ' => $ providers [0 ]->getId (),
110- 'redirectUrl ' => $ absoluteRedirectUrl
111- ]);
112- header ('Location: ' . $ targetUrl );
113- exit ();
117+ if ($ isDefaultLogin && !$ settings ->getAllowMultipleUserBackEnds ()) {
118+ $ providers = $ this ->getCachedProviders ($ providerMapper );
119+ if (count ($ providers ) === 1 ) {
120+ $ targetUrl = $ urlGenerator ->linkToRoute (self ::APP_ID . '.login.login ' , [
121+ 'providerId ' => $ providers [0 ]->getId (),
122+ 'redirectUrl ' => $ absoluteRedirectUrl
123+ ]);
124+ header ('Location: ' . $ targetUrl );
125+ exit ();
126+ }
114127 }
115128 }
116129
0 commit comments