[英]python fido2 server with if statement
我使用这个例子作为我关于 Yubikey 项目的灵感。 在authenticate.html
的末尾,我想添加一个 if 语句。 因此,如果身份验证成功,则重定向到特定页面,否则重定向回主页。 我为 if 语句尝试了不同的地方:
.then(function(response) {
var stat = response.ok ? 'successful' : 'unsuccessful';
alert('Authentication ' + stat + ' More details in server log...');
}, function(reason) {
alert(reason);
}).then(
function() {
if(stat=='successful'){
window.location.replace('https://google.com')
}
else {
window.location = '/';
}
});
}
和
.then(function(response) {
var stat = response.ok ? 'successful' : 'unsuccessful';
alert('Authentication ' + stat + ' More details in server log...');
if(stat=='successful'){
window.location.replace('https://google.com')
}
else {
window.location = '/';
}
}, function(reason) {
alert(reason);
}).then(
function() {
});
}
我以前从未见过 Javascript,但似乎我无法绕过 Yubikey 和 Python(我熟悉 python)不使用 JS。 以上都没有达到预期的效果。
假设您正在使用 fetch ,那么正确(也是最简单)的处理方式将如下所示:
fetch('some-super-secret-endpoint')
.then(response => {
if(response.ok)
window.location = 'https://google.com'
else
window.location = '/'
}).catch(e => {
console.error(e)
})
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.