1717use OCP \AppFramework \Http \Attribute \UseSession ;
1818use OCP \AppFramework \Http \RedirectResponse ;
1919use OCP \AppFramework \Http \TemplateResponse ;
20+ use OCP \IConfig ;
2021use OCP \IL10N ;
2122use OCP \IRequest ;
2223use OCP \ISession ;
@@ -31,6 +32,8 @@ class LoginRedirectorController extends Controller {
3132 private $ session ;
3233 /** @var IL10N */
3334 private $ l ;
35+ /** @var IConfig */
36+ private $ config ;
3437
3538 /**
3639 * @param string $appName
@@ -39,18 +42,21 @@ class LoginRedirectorController extends Controller {
3942 * @param ClientMapper $clientMapper
4043 * @param ISession $session
4144 * @param IL10N $l
45+ * @param IConfig $config
4246 */
4347 public function __construct (string $ appName ,
4448 IRequest $ request ,
4549 IURLGenerator $ urlGenerator ,
4650 ClientMapper $ clientMapper ,
4751 ISession $ session ,
48- IL10N $ l ) {
52+ IL10N $ l ,
53+ IConfig $ config ) {
4954 parent ::__construct ($ appName , $ request );
5055 $ this ->urlGenerator = $ urlGenerator ;
5156 $ this ->clientMapper = $ clientMapper ;
5257 $ this ->session = $ session ;
5358 $ this ->l = $ l ;
59+ $ this ->config = $ config ;
5460 }
5561
5662 /**
@@ -59,6 +65,7 @@ public function __construct(string $appName,
5965 * @param string $client_id Client ID
6066 * @param string $state State of the flow
6167 * @param string $response_type Response type for the flow
68+ * @param string $redirect_uri URI to redirect to after the flow (is only used for legacy ownCloud clients)
6269 * @return TemplateResponse<Http::STATUS_OK, array{}>|RedirectResponse<Http::STATUS_SEE_OTHER, array{}>
6370 *
6471 * 200: Client not found
@@ -69,7 +76,8 @@ public function __construct(string $appName,
6976 #[UseSession]
7077 public function authorize ($ client_id ,
7178 $ state ,
72- $ response_type ): TemplateResponse |RedirectResponse {
79+ $ response_type ,
80+ string $ redirect_uri = '' ): TemplateResponse |RedirectResponse {
7381 try {
7482 $ client = $ this ->clientMapper ->getByIdentifier ($ client_id );
7583 } catch (ClientNotFoundException $ e ) {
@@ -85,12 +93,20 @@ public function authorize($client_id,
8593 return new RedirectResponse ($ url );
8694 }
8795
96+ $ enableOcClients = $ this ->config ->getSystemValueBool ('oauth2.enable_oc_clients ' , false );
97+
98+ $ providedRedirectUri = '' ;
99+ if ($ enableOcClients && $ client ->getRedirectUri () === 'http://localhost:* ' ) {
100+ $ providedRedirectUri = $ redirect_uri ;
101+ }
102+
88103 $ this ->session ->set ('oauth.state ' , $ state );
89104
90105 $ targetUrl = $ this ->urlGenerator ->linkToRouteAbsolute (
91106 'core.ClientFlowLogin.showAuthPickerPage ' ,
92107 [
93108 'clientIdentifier ' => $ client ->getClientIdentifier (),
109+ 'providedRedirectUri ' => $ providedRedirectUri ,
94110 ]
95111 );
96112 return new RedirectResponse ($ targetUrl );
0 commit comments