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)
})

最新更新