webauthn
This commit is contained in:
parent
62dcd743fb
commit
ffd47f8ca5
|
@ -5,6 +5,10 @@ use \LAMConfig;
|
||||||
use \htmlScript;
|
use \htmlScript;
|
||||||
use \htmlIframe;
|
use \htmlIframe;
|
||||||
use \htmlImage;
|
use \htmlImage;
|
||||||
|
use \htmlButton;
|
||||||
|
use \htmlJavaScript;
|
||||||
|
use \htmlStatusMessage;
|
||||||
|
use \htmlDiv;
|
||||||
use \LAMException;
|
use \LAMException;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -519,6 +523,16 @@ class WebauthnProvider extends BaseProvider {
|
||||||
public function addCustomInput(&$row, $userDn) {
|
public function addCustomInput(&$row, $userDn) {
|
||||||
$pathPrefix = $this->config->isSelfService ? '../' : '';
|
$pathPrefix = $this->config->isSelfService ? '../' : '';
|
||||||
$row->add(new htmlImage($pathPrefix . '../graphics/webauthn.svg'), 12);
|
$row->add(new htmlImage($pathPrefix . '../graphics/webauthn.svg'), 12);
|
||||||
|
$row->addVerticalSpacer('1rem');
|
||||||
|
$registerButton = new htmlButton('register_webauthn', _('Register new key'));
|
||||||
|
$registerButton->setCSSClasses(array('fullwidth hidden'));
|
||||||
|
$row->add($registerButton, 12);
|
||||||
|
$loginButton = new htmlButton('login_webauthn', _('Login'));
|
||||||
|
$loginButton->setCSSClasses(array('fullwidth hidden'));
|
||||||
|
$row->add($loginButton, 12);
|
||||||
|
$errorMessage = new htmlStatusMessage('ERROR', '', _('This service requires a browser with webauthn support.'));
|
||||||
|
$row->add(new htmlDiv(null, $errorMessage, array('hidden webauthn-error')), 12);
|
||||||
|
$row->add(new htmlJavaScript('window.lam.webauthn.start(\'' . $pathPrefix . '\');'), 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -1356,6 +1356,52 @@ window.lam.selfservice.addMultiValue = function(fieldNamePrefix, addButton) {
|
||||||
jQuery(addButton).remove();
|
jQuery(addButton).remove();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
window.lam.webauthn = window.lam.webauthn || {};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Starts the webauthn process.
|
||||||
|
*
|
||||||
|
* @param prefix path prefix for Ajax endpoint
|
||||||
|
*/
|
||||||
|
window.lam.webauthn.start = function(prefix) {
|
||||||
|
jQuery(document).ready(
|
||||||
|
function() {
|
||||||
|
window.lam.webauthn.run(prefix);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks if the user is registered and starts login/registration.
|
||||||
|
*
|
||||||
|
* @param prefix path prefix for Ajax endpoint
|
||||||
|
*/
|
||||||
|
window.lam.webauthn.run = function(prefix) {
|
||||||
|
var token = jQuery('#sec_token').val();
|
||||||
|
// check for webauthn support
|
||||||
|
if (!navigator.credentials || (typeof(PublicKeyCredential) === "undefined")) {
|
||||||
|
jQuery('.webauthn-error').show();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var data = {
|
||||||
|
action: 'status',
|
||||||
|
sec_token: token
|
||||||
|
};
|
||||||
|
jQuery.ajax({
|
||||||
|
url: prefix + 'misc/ajax.php?function=webauthn',
|
||||||
|
method: 'POST',
|
||||||
|
data: data
|
||||||
|
})
|
||||||
|
.done(function(jsonData) {
|
||||||
|
console.log(jsonData);
|
||||||
|
})
|
||||||
|
.fail(function() {
|
||||||
|
console.log('Webauthn failed');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
jQuery(document).ready(function() {
|
jQuery(document).ready(function() {
|
||||||
window.lam.gui.equalHeight();
|
window.lam.gui.equalHeight();
|
||||||
window.lam.form.autoTrim();
|
window.lam.form.autoTrim();
|
||||||
|
|
Loading…
Reference in New Issue