]> source.dussan.org Git - nextcloud-server.git/commitdiff
Add direct arg to login flow 31592/head
authorVincent Petry <vincent@nextcloud.com>
Tue, 25 Jan 2022 16:47:58 +0000 (17:47 +0100)
committerCarl Schwan <carl@carlschwan.eu>
Mon, 28 Mar 2022 08:28:45 +0000 (10:28 +0200)
Signed-off-by: Vincent Petry <vincent@nextcloud.com>
Co-Authored-by: Carl Schwan <carl@carlschwan.eu>
core/Controller/ClientFlowLoginController.php
core/templates/loginflow/authpicker.php
core/templates/loginflow/grant.php
lib/private/AppFramework/Middleware/Security/SecurityMiddleware.php
tests/Core/Controller/ClientFlowLoginControllerTest.php

index e067f0ff6b5f5b3406f0c29c3aa2b336a40794f4..ad8bc8eb086df5b99fe7acc7a15107785bcbdd05 100644 (file)
@@ -162,12 +162,8 @@ class ClientFlowLoginController extends Controller {
         * @PublicPage
         * @NoCSRFRequired
         * @UseSession
-        *
-        * @param string $clientIdentifier
-        *
-        * @return StandaloneTemplateResponse
         */
-       public function showAuthPickerPage($clientIdentifier = '', $user = '') {
+       public function showAuthPickerPage(string $clientIdentifier = '', string $user = '', int $direct = 0): StandaloneTemplateResponse {
                $clientName = $this->getClientName();
                $client = null;
                if ($clientIdentifier !== '') {
@@ -219,6 +215,7 @@ class ClientFlowLoginController extends Controller {
                                'serverHost' => $this->getServerPath(),
                                'oauthState' => $this->session->get('oauth.state'),
                                'user' => $user,
+                               'direct' => $direct,
                        ],
                        'guest'
                );
@@ -232,13 +229,10 @@ class ClientFlowLoginController extends Controller {
         * @NoCSRFRequired
         * @NoSameSiteCookieRequired
         * @UseSession
-        *
-        * @param string $stateToken
-        * @param string $clientIdentifier
-        * @return StandaloneTemplateResponse
         */
-       public function grantPage($stateToken = '',
-                                                                $clientIdentifier = '') {
+       public function grantPage(string $stateToken = '',
+                                 string $clientIdentifier = '',
+                                 int $direct = 0): StandaloneTemplateResponse {
                if (!$this->isValidToken($stateToken)) {
                        return $this->stateTokenForbiddenResponse();
                }
@@ -268,6 +262,7 @@ class ClientFlowLoginController extends Controller {
                                'stateToken' => $stateToken,
                                'serverHost' => $this->getServerPath(),
                                'oauthState' => $this->session->get('oauth.state'),
+                               'direct' => $direct,
                        ],
                        'guest'
                );
index d8ef2998d13acf014b2f536ce5f2842d05f7744e..a7d4faa67bf18f3cb9b8f3d8aae3930049d4953a 100644 (file)
@@ -46,7 +46,7 @@ $urlGenerator = $_['urlGenerator'];
        <br/>
 
        <p id="redirect-link">
-               <a href="<?php p($urlGenerator->linkToRoute('core.ClientFlowLogin.grantPage', ['stateToken' => $_['stateToken'], 'clientIdentifier' => $_['clientIdentifier'], 'oauthState' => $_['oauthState'], 'user' => $_['user']])) ?>">
+               <a href="<?php p($urlGenerator->linkToRoute('core.ClientFlowLogin.grantPage', ['stateToken' => $_['stateToken'], 'clientIdentifier' => $_['clientIdentifier'], 'oauthState' => $_['oauthState'], 'user' => $_['user'], 'direct' => $_['direct']])) ?>">
                        <input type="submit" class="login primary icon-confirm-white" value="<?php p($l->t('Log in')) ?>">
                </a>
        </p>
@@ -62,6 +62,9 @@ $urlGenerator = $_['urlGenerator'];
                </p>
                <input type="hidden" name="stateToken" value="<?php p($_['stateToken']) ?>" />
                <input type="hidden" name="requesttoken" value="<?php p($_['requesttoken']) ?>">
+               <?php if ($_['direct'] !== 0) { ?>
+                       <input type="hidden" name="direct" value="<?php p($_['direct']) ?>">
+               <?php } ?>
                <input id="submit-app-token-login" type="submit" class="login primary icon-confirm-white" value="<?php p($l->t('Grant access')) ?>">
        </form>
 
index 0f1b9235a89717aa0c4e69432b6839d5609a4bd1..c537c47ea648807e12bed4f3a5427012bb71a118 100644 (file)
@@ -39,14 +39,17 @@ $urlGenerator = $_['urlGenerator'];
        <br/>
 
        <p id="redirect-link">
-               <form method="POST" action="<?php p($urlGenerator->linkToRouteAbsolute('core.ClientFlowLogin.generateAppPassword')) ?>">        
-                       <input type="hidden" name="clientIdentifier" value="<?php p($_['clientIdentifier']) ?>" />      
-                       <input type="hidden" name="requesttoken" value="<?php p($_['requesttoken']) ?>" />      
-                       <input type="hidden" name="stateToken" value="<?php p($_['stateToken']) ?>" />  
-                       <input type="hidden" name="oauthState" value="<?php p($_['oauthState']) ?>" />  
+               <form method="POST" action="<?php p($urlGenerator->linkToRouteAbsolute('core.ClientFlowLogin.generateAppPassword')) ?>">
+                       <input type="hidden" name="clientIdentifier" value="<?php p($_['clientIdentifier']) ?>" />
+                       <input type="hidden" name="requesttoken" value="<?php p($_['requesttoken']) ?>" />
+                       <input type="hidden" name="stateToken" value="<?php p($_['stateToken']) ?>" />
+                       <input type="hidden" name="oauthState" value="<?php p($_['oauthState']) ?>" />
+                       <?php if (p($_['direct'])) { ?>
+                       <input type="hidden" name="direct" value="1" />
+                       <?php } ?>
                        <div id="submit-wrapper">
                                <input type="submit" class="login primary icon-confirm-white" title="" value="<?php p($l->t('Grant access')); ?>" />
-                       </div>  
+                       </div>
                </form>
        </p>
 </div>
index fffeffd4feb992904dd082725ba7325704b2130a..e0f36231b68c86e68f9ad287e4965c17b31ab12e 100644 (file)
@@ -264,6 +264,9 @@ class SecurityMiddleware extends Middleware {
                                        if ($usernamePrefill !== '') {
                                                $params['user'] = $usernamePrefill;
                                        }
+                                       if ($this->request->getParam('direct')) {
+                                               $params['direct'] = 1;
+                                       }
                                        $url = $this->urlGenerator->linkToRoute('core.login.showLoginForm', $params);
                                        $response = new RedirectResponse($url);
                                } else {
index 38204bbcc32c1640f00a2d7b19987434d5a328b9..dae42474f41bd5a74043461e4892e5888873e997 100644 (file)
@@ -184,6 +184,7 @@ class ClientFlowLoginControllerTest extends TestCase {
                                'serverHost' => 'https://example.com',
                                'oauthState' => 'OauthStateToken',
                                'user' => '',
+                               'direct' => 0
                        ],
                        'guest'
                );
@@ -248,6 +249,7 @@ class ClientFlowLoginControllerTest extends TestCase {
                                'serverHost' => 'https://example.com',
                                'oauthState' => 'OauthStateToken',
                                'user' => '',
+                               'direct' => 0
                        ],
                        'guest'
                );