Skip to content

Commit 076f6b8

Browse files
authored
Merge pull request #13363 from nextcloud/fix/loginflow_apptoken_ios
Fix loginflow with apptoken enter on iOS
2 parents 40e3a7b + e6ac233 commit 076f6b8

File tree

4 files changed

+17
-11
lines changed

4 files changed

+17
-11
lines changed

core/Controller/ClientFlowLoginController.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,18 @@ public function generateAppPassword($stateToken,
327327
return new Http\RedirectResponse($redirectUri);
328328
}
329329

330+
/**
331+
* @PublicPage
332+
*/
333+
public function apptokenRedirect(string $stateToken, string $user, string $password) {
334+
if (!$this->isValidToken($stateToken)) {
335+
return $this->stateTokenForbiddenResponse();
336+
}
337+
338+
$redirectUri = 'nc://login/server:' . $this->getServerPath() . '&user:' . urlencode($user) . '&password:' . urlencode($password);
339+
return new Http\RedirectResponse($redirectUri);
340+
}
341+
330342
private function getServerPath(): string {
331343
$serverPostfix = '';
332344

core/js/login/authpicker.js

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,4 @@ jQuery(document).ready(function() {
55
$('#redirect-link').addClass('hidden');
66
$('#app-token-login-field').removeClass('hidden');
77
});
8-
9-
$('#submit-app-token-login').click(function(e) {
10-
e.preventDefault();
11-
window.location.href = 'nc://login/server:'
12-
+ encodeURIComponent($('#serverHost').val())
13-
+ "&user:" + encodeURIComponent($('#user').val())
14-
+ "&password:" + encodeURIComponent($('#password').val());
15-
});
168
});

core/routes.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
['name' => 'ClientFlowLogin#showAuthPickerPage', 'url' => '/login/flow', 'verb' => 'GET'],
5555
['name' => 'ClientFlowLogin#generateAppPassword', 'url' => '/login/flow', 'verb' => 'POST'],
5656
['name' => 'ClientFlowLogin#grantPage', 'url' => '/login/flow/grant', 'verb' => 'GET'],
57+
['name' => 'ClientFlowLogin#apptokenRedirect', 'url' => '/login/flow/apptoken', 'verb' => 'POST'],
5758
['name' => 'TwoFactorChallenge#selectChallenge', 'url' => '/login/selectchallenge', 'verb' => 'GET'],
5859
['name' => 'TwoFactorChallenge#showChallenge', 'url' => '/login/challenge/{challengeProviderId}', 'verb' => 'GET'],
5960
['name' => 'TwoFactorChallenge#solveChallenge', 'url' => '/login/challenge/{challengeProviderId}', 'verb' => 'POST'],

core/templates/loginflow/authpicker.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
</a>
4545
</p>
4646

47-
<fieldset id="app-token-login-field" class="hidden">
47+
<form action="<?php p($urlGenerator->linkToRouteAbsolute('core.ClientFlowLogin.apptokenRedirect')); ?>" method="post" id="app-token-login-field" class="hidden">
4848
<p class="grouptop">
4949
<input type="text" name="user" id="user" placeholder="<?php p($l->t('Username')) ?>">
5050
<label for="user" class="infield"><?php p($l->t('Username')) ?></label>
@@ -53,9 +53,10 @@
5353
<input type="password" name="password" id="password" placeholder="<?php p($l->t('App token')) ?>">
5454
<label for="password" class="infield"><?php p($l->t('Password')) ?></label>
5555
</p>
56-
<input type="hidden" id="serverHost" value="<?php p($_['serverHost']) ?>" />
56+
<input type="hidden" name="stateToken" value="<?php p($_['stateToken']) ?>" />
57+
<input type="hidden" name="requesttoken" value="<?php p($_['requesttoken']) ?>">
5758
<input id="submit-app-token-login" type="submit" class="login primary icon-confirm-white" value="<?php p($l->t('Grant access')) ?>">
58-
</fieldset>
59+
</form>
5960
</div>
6061

6162
<?php if(empty($_['oauthState'])): ?>

0 commit comments

Comments
 (0)