Skip to content

Commit

Permalink
v1.2.5 Fix Aborting ConditionalUI
Browse files Browse the repository at this point in the history
* Fix Disabling ConditionalUI

* Fix ConditionalUI abort

* Bump version to 1.2.5
  • Loading branch information
mkalioby committed Jul 25, 2023
1 parent 5df5514 commit 048403a
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 6 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 1.2.5

* Fix: Aborting the conditional UI was not working when 'Login by Passkeys' is clicked.

## v1.2.3

* No Change just updating README.md
Expand Down
19 changes: 14 additions & 5 deletions passkeys/templates/passkeys.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@
<script type="application/javascript" src="{% static 'passkeys/js/helpers.js' %}"></script>
<script type="text/javascript">
window.conditionalUI=false;
window.conditionUIAbortController = new AbortController();
window.conditionUIAbortSignal = conditionUIAbortController.signal;
function checkConditionalUI(form) {
if (window.PublicKeyCredential && PublicKeyCredential.isConditionalMediationAvailable) {
// Check if conditional mediation is available.
PublicKeyCredential.isConditionalMediationAvailable().then((result) => {
window.conditionalUI = result;
if (window.conditionalUI) {
authn(form)
start_authn(form,true)
}
});
}
Expand All @@ -24,7 +26,8 @@ var GetAssertReq = (getAssert) => {

return getAssert
}
function authn(form)

function start_authn(form,conditionalUI=false)
{
window.loginForm=form;
fetch('{% url 'passkeys:auth_begin' %}', {
Expand All @@ -37,9 +40,12 @@ var GetAssertReq = (getAssert) => {
}
throw new Error('No credential available to authenticate!');
}).then(function(options) {
if (window.conditionalUI) {
options.mediation= 'conditional';
if (conditionalUI) {
options.mediation = 'conditional';
options.signal = window.conditionUIAbortSignal;
}
else
window.conditionUIAbortController.abort()
console.log(options)
return navigator.credentials.get(options);
}).then(function(assertion) {
Expand All @@ -65,6 +71,9 @@ var GetAssertReq = (getAssert) => {
}
});
}

function authn(form)
{
start_authn(form,false)
}

</script>
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

setup(
name='django-passkeys',
version='1.2.4',
version='1.2.5',
description='A Django Authentication Backend for Passkeys',
long_description=open("README.md").read(),
long_description_content_type="text/markdown",
Expand Down

0 comments on commit 048403a

Please sign in to comment.