Added Abort Signal

This commit is contained in:
Mohamed El-Kalioby
2022-10-17 21:42:36 +03:00
parent 1cfddde23b
commit fcad5d3818
2 changed files with 11 additions and 7 deletions

View File

@@ -12,8 +12,11 @@ var GetAssertReq = (getAssert) => {
return getAssert return getAssert
} }
function authen() function authen(conditionalUI=false)
{ {
if (window.hasOwnProperty("getCredSignal"))
window.getCredSignal.abort('Restarting');
window.getCredSignal = new AbortController();
fetch('{% url 'fido2_begin_auth' %}', { fetch('{% url 'fido2_begin_auth' %}', {
method: 'GET', method: 'GET',
}).then(function(response) { }).then(function(response) {
@@ -25,10 +28,11 @@ var GetAssertReq = (getAssert) => {
throw new Error('No credential available to authenticate!'); throw new Error('No credential available to authenticate!');
}).then(function(options) { }).then(function(options) {
console.log(options) console.log(options)
{% if conditionalUI %} if (conditionalUI) {
options["mediation"] = 'conditional'; options.mediation = 'conditional';
{% endif %} }
return navigator.credentials.get(options); options.signal = window.getCredSignal.signal;
return navigator.credentials.get(options);
}).then(function(assertion) { }).then(function(assertion) {

View File

@@ -7,9 +7,9 @@
// Check if conditional mediation is available. // Check if conditional mediation is available.
const isCMA = await PublicKeyCredential.isConditionalMediationAvailable() const isCMA = await PublicKeyCredential.isConditionalMediationAvailable()
if (isCMA) { if (isCMA) {
authen(); authen(true);
} }
} }
}) })
</script> </script>
{% include 'FIDO2/Auth_JS.html' with conditionalUI=True %} {% include 'FIDO2/Auth_JS.html' %}