3434use OCP \AppFramework \Http ;
3535use OCP \AppFramework \Http \RedirectResponse ;
3636use OCP \AppFramework \Http \TemplateResponse ;
37+ use OCP \IConfig ;
3738use OCP \IL10N ;
3839use OCP \IRequest ;
3940use OCP \ISession ;
@@ -48,6 +49,7 @@ class LoginRedirectorController extends Controller {
4849 private $ session ;
4950 /** @var IL10N */
5051 private $ l ;
52+ private IConfig $ config ;
5153
5254 /**
5355 * @param string $appName
@@ -56,18 +58,21 @@ class LoginRedirectorController extends Controller {
5658 * @param ClientMapper $clientMapper
5759 * @param ISession $session
5860 * @param IL10N $l
61+ * @param IConfig $l
5962 */
6063 public function __construct (string $ appName ,
6164 IRequest $ request ,
6265 IURLGenerator $ urlGenerator ,
6366 ClientMapper $ clientMapper ,
6467 ISession $ session ,
65- IL10N $ l ) {
68+ IL10N $ l ,
69+ IConfig $ config ) {
6670 parent ::__construct ($ appName , $ request );
6771 $ this ->urlGenerator = $ urlGenerator ;
6872 $ this ->clientMapper = $ clientMapper ;
6973 $ this ->session = $ session ;
7074 $ this ->l = $ l ;
75+ $ this ->config = $ config ;
7176 }
7277
7378 /**
@@ -80,14 +85,16 @@ public function __construct(string $appName,
8085 * @param string $client_id Client ID
8186 * @param string $state State of the flow
8287 * @param string $response_type Response type for the flow
88+ * @param string $redirect_uri URI to redirect to after the flow (is only used for legacy ownCloud clients)
8389 * @return TemplateResponse<Http::STATUS_OK, array{}>|RedirectResponse<Http::STATUS_SEE_OTHER, array{}>
8490 *
8591 * 200: Client not found
8692 * 303: Redirect to login URL
8793 */
8894 public function authorize ($ client_id ,
8995 $ state ,
90- $ response_type ): TemplateResponse |RedirectResponse {
96+ $ response_type ,
97+ string $ redirect_uri = '' ): TemplateResponse |RedirectResponse {
9198 try {
9299 $ client = $ this ->clientMapper ->getByIdentifier ($ client_id );
93100 } catch (ClientNotFoundException $ e ) {
@@ -103,12 +110,20 @@ public function authorize($client_id,
103110 return new RedirectResponse ($ url );
104111 }
105112
113+ $ enableOcClients = $ this ->config ->getSystemValueBool ('oauth2.enable_oc_clients ' , false );
114+
115+ $ providedRedirectUri = '' ;
116+ if ($ enableOcClients && $ client ->getRedirectUri () === 'http://localhost:* ' ) {
117+ $ providedRedirectUri = $ redirect_uri ;
118+ }
119+
106120 $ this ->session ->set ('oauth.state ' , $ state );
107121
108122 $ targetUrl = $ this ->urlGenerator ->linkToRouteAbsolute (
109123 'core.ClientFlowLogin.showAuthPickerPage ' ,
110124 [
111125 'clientIdentifier ' => $ client ->getClientIdentifier (),
126+ 'providedRedirectUri ' => $ providedRedirectUri ,
112127 ]
113128 );
114129 return new RedirectResponse ($ targetUrl );
0 commit comments