Skip to content

Commit

Permalink
Fix default redirect on successful WebAuthn login
Browse files Browse the repository at this point in the history
Signed-off-by: Richard Steinmetz <[email protected]>
  • Loading branch information
st3iny committed Dec 5, 2022
1 parent e36e92b commit fc4dd30
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 8 deletions.
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.

0 comments on commit fc4dd30

Please sign in to comment.