Skip to content

Commit c38d838

Browse files
rullzerMorrisJobke
authored andcommitted
Fix loginflow with apptoken enter on iOS
It seems iOS doesn't like us to change the location. So now we submit it to the server that geneartes the redirect. Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
1 parent 3c3cb71 commit c38d838

File tree

4 files changed

+35
-11
lines changed

4 files changed

+35
-11
lines changed

core/Controller/ClientFlowLoginController.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -336,4 +336,34 @@ public function generateAppPassword($stateToken,
336336

337337
return new Http\RedirectResponse($redirectUri);
338338
}
339+
340+
/**
341+
* @PublicPage
342+
*/
343+
public function apptokenRedirect(string $stateToken, string $user, string $password) {
344+
if (!$this->isValidToken($stateToken)) {
345+
return $this->stateTokenForbiddenResponse();
346+
}
347+
348+
$redirectUri = 'nc://login/server:' . $this->getServerPath() . '&user:' . urlencode($user) . '&password:' . urlencode($password);
349+
return new Http\RedirectResponse($redirectUri);
350+
}
351+
352+
private function getServerPath(): string {
353+
$serverPostfix = '';
354+
if (strpos($this->request->getRequestUri(), '/index.php') !== false) {
355+
$serverPostfix = substr($this->request->getRequestUri(), 0, strpos($this->request->getRequestUri(), '/index.php'));
356+
} else if (strpos($this->request->getRequestUri(), '/login/flow') !== false) {
357+
$serverPostfix = substr($this->request->getRequestUri(), 0, strpos($this->request->getRequestUri(), '/login/flow'));
358+
}
359+
$protocol = $this->request->getServerProtocol();
360+
if ($protocol !== "https") {
361+
$xForwardedProto = $this->request->getHeader('X-Forwarded-Proto');
362+
$xForwardedSSL = $this->request->getHeader('X-Forwarded-Ssl');
363+
if ($xForwardedProto === 'https' || $xForwardedSSL === 'on') {
364+
$protocol = 'https';
365+
}
366+
}
367+
return $protocol . "://" . $this->request->getServerHost() . $serverPostfix;
368+
}
339369
}

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
@@ -53,6 +53,7 @@
5353
['name' => 'ClientFlowLogin#showAuthPickerPage', 'url' => '/login/flow', 'verb' => 'GET'],
5454
['name' => 'ClientFlowLogin#redirectPage', 'url' => '/login/flow/redirect', 'verb' => 'GET'],
5555
['name' => 'ClientFlowLogin#generateAppPassword', 'url' => '/login/flow', 'verb' => 'POST'],
56+
['name' => 'ClientFlowLogin#apptokenRedirect', 'url' => '/login/flow/apptoken', 'verb' => 'POST'],
5657
['name' => 'TwoFactorChallenge#selectChallenge', 'url' => '/login/selectchallenge', 'verb' => 'GET'],
5758
['name' => 'TwoFactorChallenge#showChallenge', 'url' => '/login/challenge/{challengeProviderId}', 'verb' => 'GET'],
5859
['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)