Skip to content
Snippets Groups Projects
Verified Commit 8ff3a557 authored by Pavel Břoušek's avatar Pavel Břoušek
Browse files

fix: improve behavior when preferredToken=webAuthn in unsupported browser

switch method to OTP only once
parent b01e34c1
No related branches found
No related tags found
1 merge request!1Improve WebAuthn user experience
...@@ -60,6 +60,14 @@ function changeMode(newMode) { ...@@ -60,6 +60,14 @@ function changeMode(newMode) {
document.forms["piLoginForm"].submit(); document.forms["piLoginForm"].submit();
} }
function fallbackToOTP() {
if (value("mode") !== "otp") {
setTimeout(() => {
changeMode("otp");
}, 3000);
}
}
function setMessage(newMessage) { function setMessage(newMessage) {
getElement("message").innerText = newMessage; getElement("message").innerText = newMessage;
} }
...@@ -113,14 +121,14 @@ function doWebAuthn() { ...@@ -113,14 +121,14 @@ function doWebAuthn() {
console.log( console.log(
"Insecure context detected: Aborting Web Authn authentication!" "Insecure context detected: Aborting Web Authn authentication!"
); );
changeMode("otp"); fallbackToOTP();
return; return;
} }
if (!window.pi_webauthn) { if (!window.pi_webauthn) {
enable("useWebAuthnButton"); enable("useWebAuthnButton");
setMessage(t("webauthn_library_unavailable")); setMessage(t("webauthn_library_unavailable"));
changeMode("otp"); fallbackToOTP();
return; return;
} }
...@@ -163,7 +171,7 @@ function doU2F() { ...@@ -163,7 +171,7 @@ function doU2F() {
if (!window.isSecureContext) { if (!window.isSecureContext) {
setMessage(t("u2f_insecure_context")); setMessage(t("u2f_insecure_context"));
console.log("Insecure context detected: Aborting U2F authentication!"); console.log("Insecure context detected: Aborting U2F authentication!");
changeMode("otp"); fallbackToOTP();
return; return;
} }
...@@ -171,7 +179,7 @@ function doU2F() { ...@@ -171,7 +179,7 @@ function doU2F() {
if (requestStr === null) { if (requestStr === null) {
setMessage(t("u2f_unavailable")); setMessage(t("u2f_unavailable"));
changeMode("otp"); fallbackToOTP();
return; return;
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment