Skip to content

Commit 6de8ca8

Browse files
committed
fix: update request token on two-factor pages
Signed-off-by: Richard Steinmetz <richard@steinmetz.cloud>
1 parent 1d7fc28 commit 6de8ca8

13 files changed

+78
-7
lines changed

core/Controller/TwoFactorChallengeController.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
use OCP\ISession;
2626
use OCP\IURLGenerator;
2727
use OCP\IUserSession;
28+
use OCP\Util;
2829
use Psr\Log\LoggerInterface;
2930

3031
#[OpenAPI(scope: OpenAPI::SCOPE_IGNORE)]
@@ -89,6 +90,7 @@ public function selectChallenge($redirect_url) {
8990
'logout_url' => $this->getLogoutUrl(),
9091
'hasSetupProviders' => !empty($setupProviders),
9192
];
93+
Util::addScript('core', 'twofactor-request-token');
9294
return new StandaloneTemplateResponse($this->appName, 'twofactorselectchallenge', $data, 'guest');
9395
}
9496

@@ -141,6 +143,7 @@ public function showChallenge($challengeProviderId, $redirect_url) {
141143
if ($provider instanceof IProvidesCustomCSP) {
142144
$response->setContentSecurityPolicy($provider->getCSP());
143145
}
146+
Util::addScript('core', 'twofactor-request-token');
144147
return $response;
145148
}
146149

@@ -204,6 +207,7 @@ public function setupProviders(?string $redirect_url = null): StandaloneTemplate
204207
'redirect_url' => $redirect_url,
205208
];
206209

210+
Util::addScript('core', 'twofactor-request-token');
207211
return new StandaloneTemplateResponse($this->appName, 'twofactorsetupselection', $data, 'guest');
208212
}
209213

@@ -235,6 +239,7 @@ public function setupProvider(string $providerId, ?string $redirect_url = null)
235239
'template' => $tmpl->fetchPage(),
236240
];
237241
$response = new StandaloneTemplateResponse($this->appName, 'twofactorsetupchallenge', $data, 'guest');
242+
Util::addScript('core', 'twofactor-request-token');
238243
return $response;
239244
}
240245

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/**
2+
* SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors
3+
* SPDX-License-Identifier: AGPL-3.0-or-later
4+
*/
5+
6+
import { onRequestTokenUpdate } from '@nextcloud/auth'
7+
import { getBaseUrl } from '@nextcloud/router'
8+
9+
document.addEventListener('DOMContentLoaded', () => {
10+
onRequestTokenUpdate((token) => {
11+
const cancelLink = window.document.getElementById('cancel-login')
12+
if (!cancelLink) {
13+
return
14+
}
15+
16+
const href = cancelLink.getAttribute('href')
17+
if (!href) {
18+
return
19+
}
20+
21+
const parsedHref = new URL(href, getBaseUrl())
22+
parsedHref.searchParams.set('requesttoken', token)
23+
cancelLink.setAttribute('href', parsedHref.pathname + parsedHref.search)
24+
})
25+
})

core/templates/twofactorselectchallenge.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@
7676
</a>
7777
</p>
7878
<?php endif; ?>
79-
<p><a class="two-factor-secondary" href="<?php print_unescaped($_['logout_url']); ?>">
79+
<p><a id="cancel-login" class="two-factor-secondary" href="<?php print_unescaped($_['logout_url']); ?>">
8080
<?php p($l->t('Cancel login')) ?>
8181
</a></p>
8282
</div>

core/templates/twofactorsetupchallenge.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
<div class="body-login-container update">
1515
<h2 class="two-factor-header"><?php p($provider->getDisplayName()); ?></h2>
1616
<?php print_unescaped($template); ?>
17-
<p><a class="two-factor-secondary" href="<?php print_unescaped($_['logout_url']); ?>">
17+
<p><a id="cancel-login" class="two-factor-secondary" href="<?php print_unescaped($_['logout_url']); ?>">
1818
<?php p($l->t('Cancel login')) ?>
1919
</a></p>
2020
</div>

core/templates/twofactorsetupselection.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
</li>
3636
<?php endforeach; ?>
3737
</ul>
38-
<p><a class="two-factor-secondary" href="<?php print_unescaped($_['logout_url']); ?>">
38+
<p><a id="cancel-login" class="two-factor-secondary" href="<?php print_unescaped($_['logout_url']); ?>">
3939
<?php p($l->t('Cancel login')) ?>
4040
</a></p>
4141
</div>

core/templates/twofactorshowchallenge.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
</a>
3939
</p>
4040
<?php endif; ?>
41-
<p><a class="two-factor-secondary" href="<?php print_unescaped($_['logout_url']); ?>">
41+
<p><a id="cancel-login" class="two-factor-secondary" href="<?php print_unescaped($_['logout_url']); ?>">
4242
<?php p($l->t('Cancel login')) ?>
4343
</a></p>
4444
</div>

dist/core-common.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/core-common.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/core-twofactor-request-token.js

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
SPDX-License-Identifier: MIT
2+
SPDX-License-Identifier: ISC
3+
SPDX-License-Identifier: GPL-3.0-or-later
4+
SPDX-License-Identifier: AGPL-3.0-or-later
5+
SPDX-FileCopyrightText: Tobias Koppers @sokra
6+
SPDX-FileCopyrightText: Roman Shtylman <shtylman@gmail.com>
7+
SPDX-FileCopyrightText: Nextcloud GmbH and Nextcloud contributors
8+
SPDX-FileCopyrightText: GitHub Inc.
9+
SPDX-FileCopyrightText: Christoph Wurst
10+
11+
12+
This file is generated from multiple sources. Included packages:
13+
- @nextcloud/auth
14+
- version: 2.5.1
15+
- license: GPL-3.0-or-later
16+
- @nextcloud/browser-storage
17+
- version: 0.4.0
18+
- license: GPL-3.0-or-later
19+
- semver
20+
- version: 7.6.3
21+
- license: ISC
22+
- @nextcloud/event-bus
23+
- version: 3.3.2
24+
- license: GPL-3.0-or-later
25+
- @nextcloud/router
26+
- version: 3.0.1
27+
- license: GPL-3.0-or-later
28+
- process
29+
- version: 0.11.10
30+
- license: MIT
31+
- webpack
32+
- version: 5.99.9
33+
- license: MIT
34+
- nextcloud
35+
- version: 1.0.0
36+
- license: AGPL-3.0-or-later

0 commit comments

Comments
 (0)