Skip to content

Commit 032e55e

Browse files
PVince81CarlSchwan
andcommitted
Add direct arg to login flow
Signed-off-by: Vincent Petry <vincent@nextcloud.com> Co-Authored-by: Carl Schwan <carl@carlschwan.eu>
1 parent 3e067ed commit 032e55e

File tree

4 files changed

+22
-18
lines changed

4 files changed

+22
-18
lines changed

core/Controller/ClientFlowLoginController.php

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -162,12 +162,8 @@ private function stateTokenForbiddenResponse() {
162162
* @PublicPage
163163
* @NoCSRFRequired
164164
* @UseSession
165-
*
166-
* @param string $clientIdentifier
167-
*
168-
* @return StandaloneTemplateResponse
169165
*/
170-
public function showAuthPickerPage($clientIdentifier = '', $user = '') {
166+
public function showAuthPickerPage(string $clientIdentifier = '', string $user = '', int $direct = 0): StandaloneTemplateResponse {
171167
$clientName = $this->getClientName();
172168
$client = null;
173169
if ($clientIdentifier !== '') {
@@ -219,6 +215,7 @@ public function showAuthPickerPage($clientIdentifier = '', $user = '') {
219215
'serverHost' => $this->getServerPath(),
220216
'oauthState' => $this->session->get('oauth.state'),
221217
'user' => $user,
218+
'direct' => $direct,
222219
],
223220
'guest'
224221
);
@@ -232,13 +229,10 @@ public function showAuthPickerPage($clientIdentifier = '', $user = '') {
232229
* @NoCSRFRequired
233230
* @NoSameSiteCookieRequired
234231
* @UseSession
235-
*
236-
* @param string $stateToken
237-
* @param string $clientIdentifier
238-
* @return StandaloneTemplateResponse
239232
*/
240-
public function grantPage($stateToken = '',
241-
$clientIdentifier = '') {
233+
public function grantPage(string $stateToken = '',
234+
string $clientIdentifier = '',
235+
int $direct = 0): StandaloneTemplateResponse {
242236
if (!$this->isValidToken($stateToken)) {
243237
return $this->stateTokenForbiddenResponse();
244238
}
@@ -268,6 +262,7 @@ public function grantPage($stateToken = '',
268262
'stateToken' => $stateToken,
269263
'serverHost' => $this->getServerPath(),
270264
'oauthState' => $this->session->get('oauth.state'),
265+
'direct' => $direct,
271266
],
272267
'guest'
273268
);

core/templates/loginflow/authpicker.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
<br/>
4747

4848
<p id="redirect-link">
49-
<a href="<?php p($urlGenerator->linkToRoute('core.ClientFlowLogin.grantPage', ['stateToken' => $_['stateToken'], 'clientIdentifier' => $_['clientIdentifier'], 'oauthState' => $_['oauthState'], 'user' => $_['user']])) ?>">
49+
<a href="<?php p($urlGenerator->linkToRoute('core.ClientFlowLogin.grantPage', ['stateToken' => $_['stateToken'], 'clientIdentifier' => $_['clientIdentifier'], 'oauthState' => $_['oauthState'], 'user' => $_['user'], 'direct' => $_['direct']])) ?>">
5050
<input type="submit" class="login primary icon-confirm-white" value="<?php p($l->t('Log in')) ?>">
5151
</a>
5252
</p>
@@ -62,6 +62,9 @@
6262
</p>
6363
<input type="hidden" name="stateToken" value="<?php p($_['stateToken']) ?>" />
6464
<input type="hidden" name="requesttoken" value="<?php p($_['requesttoken']) ?>">
65+
<?php if ($_['direct'] !== 0) { ?>
66+
<input type="hidden" name="direct" value="<?php p($_['direct']) ?>">
67+
<?php } ?>
6568
<input id="submit-app-token-login" type="submit" class="login primary icon-confirm-white" value="<?php p($l->t('Grant access')) ?>">
6669
</form>
6770

core/templates/loginflow/grant.php

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,17 @@
3939
<br/>
4040

4141
<p id="redirect-link">
42-
<form method="POST" action="<?php p($urlGenerator->linkToRouteAbsolute('core.ClientFlowLogin.generateAppPassword')) ?>">
43-
<input type="hidden" name="clientIdentifier" value="<?php p($_['clientIdentifier']) ?>" />
44-
<input type="hidden" name="requesttoken" value="<?php p($_['requesttoken']) ?>" />
45-
<input type="hidden" name="stateToken" value="<?php p($_['stateToken']) ?>" />
46-
<input type="hidden" name="oauthState" value="<?php p($_['oauthState']) ?>" />
42+
<form method="POST" action="<?php p($urlGenerator->linkToRouteAbsolute('core.ClientFlowLogin.generateAppPassword')) ?>">
43+
<input type="hidden" name="clientIdentifier" value="<?php p($_['clientIdentifier']) ?>" />
44+
<input type="hidden" name="requesttoken" value="<?php p($_['requesttoken']) ?>" />
45+
<input type="hidden" name="stateToken" value="<?php p($_['stateToken']) ?>" />
46+
<input type="hidden" name="oauthState" value="<?php p($_['oauthState']) ?>" />
47+
<?php if (p($_['direct'])) { ?>
48+
<input type="hidden" name="direct" value="1" />
49+
<?php } ?>
4750
<div id="submit-wrapper">
4851
<input type="submit" class="login primary icon-confirm-white" title="" value="<?php p($l->t('Grant access')); ?>" />
49-
</div>
52+
</div>
5053
</form>
5154
</p>
5255
</div>

lib/private/AppFramework/Middleware/Security/SecurityMiddleware.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,9 @@ public function afterException($controller, $methodName, \Exception $exception):
264264
if ($usernamePrefill !== '') {
265265
$params['user'] = $usernamePrefill;
266266
}
267+
if ($this->request->getParam('direct')) {
268+
$params['direct'] = 1;
269+
}
267270
$url = $this->urlGenerator->linkToRoute('core.login.showLoginForm', $params);
268271
$response = new RedirectResponse($url);
269272
} else {

0 commit comments

Comments
 (0)