Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix default redirect on successful WebAuthn login #35604

Merged
merged 1 commit into from
Dec 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions core/Controller/WebAuthnController.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
*
* @author Christoph Wurst <[email protected]>
* @author Roeland Jago Douma <[email protected]>
* @author Richard Steinmetz <[email protected]>
*
* @license GNU AGPL version 3 or any later version
*
Expand All @@ -29,6 +30,7 @@
use OC\Authentication\Login\LoginData;
use OC\Authentication\Login\WebAuthnChain;
use OC\Authentication\WebAuthn\Manager;
use OC\URLGenerator;
use OCP\AppFramework\Controller;
use OCP\AppFramework\Http;
use OCP\AppFramework\Http\JSONResponse;
Expand All @@ -46,14 +48,16 @@ class WebAuthnController extends Controller {
private ISession $session;
private LoggerInterface $logger;
private WebAuthnChain $webAuthnChain;
private UrlGenerator $urlGenerator;

public function __construct($appName, IRequest $request, Manager $webAuthnManger, ISession $session, LoggerInterface $logger, WebAuthnChain $webAuthnChain) {
public function __construct($appName, IRequest $request, Manager $webAuthnManger, ISession $session, LoggerInterface $logger, WebAuthnChain $webAuthnChain, URLGenerator $urlGenerator) {
parent::__construct($appName, $request);

$this->webAuthnManger = $webAuthnManger;
$this->session = $session;
$this->logger = $logger;
$this->webAuthnChain = $webAuthnChain;
$this->urlGenerator = $urlGenerator;
}

/**
Expand Down Expand Up @@ -106,6 +110,8 @@ public function finishAuthentication(string $data): JSONResponse {
);
$this->webAuthnChain->process($loginData);

return new JSONResponse([]);
return new JSONResponse([
'defaultRedirectUrl' => $this->urlGenerator->linkToDefaultPageUrl(),
]);
}
}
7 changes: 4 additions & 3 deletions core/src/components/login/PasswordLessLoginForm.vue
Original file line number Diff line number Diff line change
Expand Up @@ -200,12 +200,13 @@ export default {
completeAuthentication(challenge) {
console.debug('TIME TO COMPLETE')

const location = this.redirectUrl
const redirectUrl = this.redirectUrl

return finishAuthentication(JSON.stringify(challenge))
.then(data => {
.then(({ defaultRedirectUrl }) => {
console.debug('Logged in redirecting')
window.location.href = location
// Redirect url might be false so || should be used instead of ??.
window.location.href = redirectUrl || defaultRedirectUrl
})
.catch(error => {
console.debug('GOT AN ERROR WHILE SUBMITTING CHALLENGE!')
Expand Down
4 changes: 2 additions & 2 deletions dist/core-login.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/core-login.js.map

Large diffs are not rendered by default.