ES5
This commit is contained in:
parent
d9fd4b36e2
commit
7d1c2afd21
|
@ -1393,7 +1393,7 @@ window.lam.webauthn.start = function(prefix, isSelfService) {
|
||||||
*/
|
*/
|
||||||
window.lam.webauthn.run = function(prefix, isSelfService) {
|
window.lam.webauthn.run = function(prefix, isSelfService) {
|
||||||
jQuery('#btn_skip_webauthn').click(function () {
|
jQuery('#btn_skip_webauthn').click(function () {
|
||||||
let form = jQuery("#2faform");
|
var form = jQuery("#2faform");
|
||||||
form.append('<input type="hidden" name="sig_response" value="skip"/>');
|
form.append('<input type="hidden" name="sig_response" value="skip"/>');
|
||||||
form.submit();
|
form.submit();
|
||||||
return;
|
return;
|
||||||
|
@ -1425,9 +1425,9 @@ window.lam.webauthn.run = function(prefix, isSelfService) {
|
||||||
form.submit();
|
form.submit();
|
||||||
};
|
};
|
||||||
const errorCallback = function(error) {
|
const errorCallback = function(error) {
|
||||||
let errorDiv = jQuery('#generic-webauthn-error');
|
var errorDiv = jQuery('#generic-webauthn-error');
|
||||||
let buttonLabel = errorDiv.data('button');
|
var buttonLabel = errorDiv.data('button');
|
||||||
let dialogTitle = errorDiv.data('title');
|
var dialogTitle = errorDiv.data('title');
|
||||||
errorDiv.text(error.message);
|
errorDiv.text(error.message);
|
||||||
window.lam.dialog.showMessage(dialogTitle,
|
window.lam.dialog.showMessage(dialogTitle,
|
||||||
buttonLabel,
|
buttonLabel,
|
||||||
|
@ -1460,18 +1460,18 @@ window.lam.webauthn.register = function(publicKey, successCallback, errorCallbac
|
||||||
publicKey.user.id = Uint8Array.from(window.atob(publicKey.user.id), c=>c.charCodeAt(0));
|
publicKey.user.id = Uint8Array.from(window.atob(publicKey.user.id), c=>c.charCodeAt(0));
|
||||||
publicKey.rp.icon = window.location.href.substring(0, window.location.href.lastIndexOf("/")) + publicKey.rp.icon;
|
publicKey.rp.icon = window.location.href.substring(0, window.location.href.lastIndexOf("/")) + publicKey.rp.icon;
|
||||||
if (publicKey.excludeCredentials) {
|
if (publicKey.excludeCredentials) {
|
||||||
for (let i = 0; i < publicKey.excludeCredentials.length; i++) {
|
for (var i = 0; i < publicKey.excludeCredentials.length; i++) {
|
||||||
let idOrig = publicKey.excludeCredentials[i]['id'];
|
var idOrig = publicKey.excludeCredentials[i]['id'];
|
||||||
idOrig = idOrig.replace(/-/g, "+").replace(/_/g, "/");
|
idOrig = idOrig.replace(/-/g, "+").replace(/_/g, "/");
|
||||||
let idOrigDecoded = atob(idOrig);
|
var idOrigDecoded = atob(idOrig);
|
||||||
let idArray = Uint8Array.from(idOrigDecoded, c => c.charCodeAt(0))
|
var idArray = Uint8Array.from(idOrigDecoded, c => c.charCodeAt(0))
|
||||||
publicKey.excludeCredentials[i]['id'] = idArray;
|
publicKey.excludeCredentials[i]['id'] = idArray;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
navigator.credentials.create({publicKey})
|
navigator.credentials.create({publicKey})
|
||||||
.then(function (data) {
|
.then(function (data) {
|
||||||
const publicKeyCredential = {
|
var publicKeyCredential = {
|
||||||
id: data.id,
|
id: data.id,
|
||||||
type: data.type,
|
type: data.type,
|
||||||
rawId: window.lam.webauthn.arrayToBase64String(new Uint8Array(data.rawId)),
|
rawId: window.lam.webauthn.arrayToBase64String(new Uint8Array(data.rawId)),
|
||||||
|
@ -1494,16 +1494,16 @@ window.lam.webauthn.register = function(publicKey, successCallback, errorCallbac
|
||||||
*/
|
*/
|
||||||
window.lam.webauthn.authenticate = function(publicKey) {
|
window.lam.webauthn.authenticate = function(publicKey) {
|
||||||
publicKey.challenge = Uint8Array.from(window.atob(publicKey.challenge), c => c.charCodeAt(0));
|
publicKey.challenge = Uint8Array.from(window.atob(publicKey.challenge), c => c.charCodeAt(0));
|
||||||
for (let i = 0; i < publicKey.allowCredentials.length; i++) {
|
for (var i = 0; i < publicKey.allowCredentials.length; i++) {
|
||||||
let idOrig = publicKey.allowCredentials[i]['id'];
|
var idOrig = publicKey.allowCredentials[i]['id'];
|
||||||
idOrig = idOrig.replace(/-/g, "+").replace(/_/g, "/");
|
idOrig = idOrig.replace(/-/g, "+").replace(/_/g, "/");
|
||||||
let idOrigDecoded = atob(idOrig);
|
var idOrigDecoded = atob(idOrig);
|
||||||
let idArray = Uint8Array.from(idOrigDecoded, c => c.charCodeAt(0))
|
var idArray = Uint8Array.from(idOrigDecoded, c => c.charCodeAt(0))
|
||||||
publicKey.allowCredentials[i]['id'] = idArray;
|
publicKey.allowCredentials[i]['id'] = idArray;
|
||||||
}
|
}
|
||||||
navigator.credentials.get({publicKey})
|
navigator.credentials.get({publicKey})
|
||||||
.then(data => {
|
.then(data => {
|
||||||
let publicKeyCredential = {
|
var publicKeyCredential = {
|
||||||
id: data.id,
|
id: data.id,
|
||||||
type: data.type,
|
type: data.type,
|
||||||
rawId: window.lam.webauthn.arrayToBase64String(new Uint8Array(data.rawId)),
|
rawId: window.lam.webauthn.arrayToBase64String(new Uint8Array(data.rawId)),
|
||||||
|
@ -1514,15 +1514,15 @@ window.lam.webauthn.authenticate = function(publicKey) {
|
||||||
userHandle: data.response.userHandle ? window.lam.webauthn.arrayToBase64String(new Uint8Array(data.response.userHandle)) : null
|
userHandle: data.response.userHandle ? window.lam.webauthn.arrayToBase64String(new Uint8Array(data.response.userHandle)) : null
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
let form = jQuery("#2faform");
|
var form = jQuery("#2faform");
|
||||||
let response = btoa(JSON.stringify(publicKeyCredential));
|
var response = btoa(JSON.stringify(publicKeyCredential));
|
||||||
form.append('<input type="hidden" name="sig_response" value="' + response + '"/>');
|
form.append('<input type="hidden" name="sig_response" value="' + response + '"/>');
|
||||||
form.submit();
|
form.submit();
|
||||||
}, error => {
|
}, error => {
|
||||||
console.log(error.message);
|
console.log(error.message);
|
||||||
let errorDiv = jQuery('#generic-webauthn-error');
|
var errorDiv = jQuery('#generic-webauthn-error');
|
||||||
let buttonLabel = errorDiv.data('button');
|
var buttonLabel = errorDiv.data('button');
|
||||||
let dialogTitle = errorDiv.data('title');
|
var dialogTitle = errorDiv.data('title');
|
||||||
errorDiv.text(error.message);
|
errorDiv.text(error.message);
|
||||||
window.lam.dialog.showMessage(dialogTitle,
|
window.lam.dialog.showMessage(dialogTitle,
|
||||||
buttonLabel,
|
buttonLabel,
|
||||||
|
@ -1547,11 +1547,11 @@ window.lam.webauthn.arrayToBase64String = function(input) {
|
||||||
* Sets up the device management on the main configuration page.
|
* Sets up the device management on the main configuration page.
|
||||||
*/
|
*/
|
||||||
window.lam.webauthn.setupDeviceManagement = function() {
|
window.lam.webauthn.setupDeviceManagement = function() {
|
||||||
const searchButton = jQuery('#btn_webauthn_search');
|
var searchButton = jQuery('#btn_webauthn_search');
|
||||||
if (searchButton) {
|
if (searchButton) {
|
||||||
searchButton.click(window.lam.webauthn.searchDevices);
|
searchButton.click(window.lam.webauthn.searchDevices);
|
||||||
}
|
}
|
||||||
const searchInput = jQuery('#webauthn_searchTerm');
|
var searchInput = jQuery('#webauthn_searchTerm');
|
||||||
if (searchInput) {
|
if (searchInput) {
|
||||||
searchInput.keydown(function (event) {
|
searchInput.keydown(function (event) {
|
||||||
if (event.keyCode == 13) {
|
if (event.keyCode == 13) {
|
||||||
|
@ -1573,10 +1573,10 @@ window.lam.webauthn.searchDevices = function(event) {
|
||||||
if (event !== null) {
|
if (event !== null) {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
}
|
}
|
||||||
const resultDiv = jQuery('#webauthn_results');
|
var resultDiv = jQuery('#webauthn_results');
|
||||||
const tokenValue = resultDiv.data('sec_token_value');
|
var tokenValue = resultDiv.data('sec_token_value');
|
||||||
const searchData = jQuery('#webauthn_searchTerm').val();
|
var searchData = jQuery('#webauthn_searchTerm').val();
|
||||||
const data = {
|
var data = {
|
||||||
action: 'search',
|
action: 'search',
|
||||||
jsonInput: '',
|
jsonInput: '',
|
||||||
sec_token: tokenValue,
|
sec_token: tokenValue,
|
||||||
|
@ -1601,7 +1601,7 @@ window.lam.webauthn.searchDevices = function(event) {
|
||||||
* Adds listeners to the device action buttons.
|
* Adds listeners to the device action buttons.
|
||||||
*/
|
*/
|
||||||
window.lam.webauthn.addDeviceActionListeners = function() {
|
window.lam.webauthn.addDeviceActionListeners = function() {
|
||||||
const inputs = jQuery('.webauthn-delete');
|
var inputs = jQuery('.webauthn-delete');
|
||||||
inputs.each(function() {
|
inputs.each(function() {
|
||||||
jQuery(this).click(function(event) {
|
jQuery(this).click(function(event) {
|
||||||
window.lam.webauthn.removeDevice(event);
|
window.lam.webauthn.removeDevice(event);
|
||||||
|
@ -1616,7 +1616,7 @@ window.lam.webauthn.addDeviceActionListeners = function() {
|
||||||
*/
|
*/
|
||||||
window.lam.webauthn.removeDevice = function(event) {
|
window.lam.webauthn.removeDevice = function(event) {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
const element = jQuery(event.target);
|
var element = jQuery(event.target);
|
||||||
window.lam.webauthn.removeDeviceDialog(element, 'webauthnDevices');
|
window.lam.webauthn.removeDeviceDialog(element, 'webauthnDevices');
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -1629,11 +1629,11 @@ window.lam.webauthn.removeDevice = function(event) {
|
||||||
*/
|
*/
|
||||||
window.lam.webauthn.removeOwnDevice = function(event, isSelfService) {
|
window.lam.webauthn.removeOwnDevice = function(event, isSelfService) {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
const element = jQuery(event.currentTarget);
|
var element = jQuery(event.currentTarget);
|
||||||
let successCallback = null;
|
var successCallback = null;
|
||||||
if (!isSelfService) {
|
if (!isSelfService) {
|
||||||
successCallback = function () {
|
successCallback = function () {
|
||||||
const form = jQuery("#webauthnform");
|
var form = jQuery("#webauthnform");
|
||||||
jQuery('<input>').attr({
|
jQuery('<input>').attr({
|
||||||
type: 'hidden',
|
type: 'hidden',
|
||||||
name: 'removed',
|
name: 'removed',
|
||||||
|
@ -1642,7 +1642,7 @@ window.lam.webauthn.removeOwnDevice = function(event, isSelfService) {
|
||||||
form.submit();
|
form.submit();
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
let action = 'webauthnOwnDevices';
|
var action = 'webauthnOwnDevices';
|
||||||
if (isSelfService) {
|
if (isSelfService) {
|
||||||
action = action + '&selfservice=true&module=webauthn&scope=user';
|
action = action + '&selfservice=true&module=webauthn&scope=user';
|
||||||
}
|
}
|
||||||
|
@ -1658,10 +1658,10 @@ window.lam.webauthn.removeOwnDevice = function(event, isSelfService) {
|
||||||
* @param successCallback callback if all was fine (optional)
|
* @param successCallback callback if all was fine (optional)
|
||||||
*/
|
*/
|
||||||
window.lam.webauthn.removeDeviceDialog = function(element, action, successCallback) {
|
window.lam.webauthn.removeDeviceDialog = function(element, action, successCallback) {
|
||||||
const dialogTitle = element.data('dialogtitle');
|
var dialogTitle = element.data('dialogtitle');
|
||||||
const okText = element.data('oktext');
|
var okText = element.data('oktext');
|
||||||
const cancelText = element.data('canceltext');
|
var cancelText = element.data('canceltext');
|
||||||
let buttonList = {};
|
var buttonList = {};
|
||||||
buttonList[okText] = function() {
|
buttonList[okText] = function() {
|
||||||
jQuery('#webauthnDeleteConfirm').dialog('close');
|
jQuery('#webauthnDeleteConfirm').dialog('close');
|
||||||
window.lam.webauthn.sendRemoveDeviceRequest(element, action, successCallback);
|
window.lam.webauthn.sendRemoveDeviceRequest(element, action, successCallback);
|
||||||
|
@ -1686,11 +1686,11 @@ window.lam.webauthn.removeDeviceDialog = function(element, action, successCallba
|
||||||
* @param successCallback callback if all was fine (optional)
|
* @param successCallback callback if all was fine (optional)
|
||||||
*/
|
*/
|
||||||
window.lam.webauthn.sendRemoveDeviceRequest = function(element, action, successCallback) {
|
window.lam.webauthn.sendRemoveDeviceRequest = function(element, action, successCallback) {
|
||||||
const dn = element.data('dn');
|
var dn = element.data('dn');
|
||||||
const credential = element.data('credential');
|
var credential = element.data('credential');
|
||||||
const resultDiv = jQuery('#webauthn_results');
|
var resultDiv = jQuery('#webauthn_results');
|
||||||
const tokenValue = resultDiv.data('sec_token_value');
|
var tokenValue = resultDiv.data('sec_token_value');
|
||||||
const data = {
|
var data = {
|
||||||
action: 'delete',
|
action: 'delete',
|
||||||
jsonInput: '',
|
jsonInput: '',
|
||||||
sec_token: tokenValue,
|
sec_token: tokenValue,
|
||||||
|
@ -1723,20 +1723,20 @@ window.lam.webauthn.sendRemoveDeviceRequest = function(element, action, successC
|
||||||
*/
|
*/
|
||||||
window.lam.webauthn.registerOwnDevice = function(event, isSelfService) {
|
window.lam.webauthn.registerOwnDevice = function(event, isSelfService) {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
const element = jQuery(event.target);
|
var element = jQuery(event.target);
|
||||||
const dn = element.data('dn');
|
var dn = element.data('dn');
|
||||||
const tokenValue = element.data('sec_token_value');
|
var tokenValue = element.data('sec_token_value');
|
||||||
const publicKey = element.data('publickey');
|
var publicKey = element.data('publickey');
|
||||||
let successCallback = function (publicKeyCredential) {
|
var successCallback = function (publicKeyCredential) {
|
||||||
const form = jQuery("#webauthnform");
|
var form = jQuery("#webauthnform");
|
||||||
const response = btoa(JSON.stringify(publicKeyCredential));
|
var response = btoa(JSON.stringify(publicKeyCredential));
|
||||||
const registrationData = jQuery('#registrationData');
|
var registrationData = jQuery('#registrationData');
|
||||||
registrationData.val(response);
|
registrationData.val(response);
|
||||||
form.submit();
|
form.submit();
|
||||||
};
|
};
|
||||||
if (isSelfService) {
|
if (isSelfService) {
|
||||||
successCallback = function (publicKeyCredential) {
|
successCallback = function (publicKeyCredential) {
|
||||||
const data = {
|
var data = {
|
||||||
action: 'register',
|
action: 'register',
|
||||||
jsonInput: '',
|
jsonInput: '',
|
||||||
sec_token: tokenValue,
|
sec_token: tokenValue,
|
||||||
|
@ -1749,7 +1749,7 @@ window.lam.webauthn.registerOwnDevice = function(event, isSelfService) {
|
||||||
data: data
|
data: data
|
||||||
})
|
})
|
||||||
.done(function(jsonData) {
|
.done(function(jsonData) {
|
||||||
const resultDiv = jQuery('#webauthn_results');
|
var resultDiv = jQuery('#webauthn_results');
|
||||||
resultDiv.html(jsonData.content);
|
resultDiv.html(jsonData.content);
|
||||||
})
|
})
|
||||||
.fail(function() {
|
.fail(function() {
|
||||||
|
@ -1757,10 +1757,10 @@ window.lam.webauthn.registerOwnDevice = function(event, isSelfService) {
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
const errorCallback = function (error) {
|
var errorCallback = function (error) {
|
||||||
let errorDiv = jQuery('#generic-webauthn-error');
|
var errorDiv = jQuery('#generic-webauthn-error');
|
||||||
let buttonLabel = errorDiv.data('button');
|
var buttonLabel = errorDiv.data('button');
|
||||||
let dialogTitle = errorDiv.data('title');
|
var dialogTitle = errorDiv.data('title');
|
||||||
errorDiv.text(error.message);
|
errorDiv.text(error.message);
|
||||||
window.lam.dialog.showMessage(dialogTitle,
|
window.lam.dialog.showMessage(dialogTitle,
|
||||||
buttonLabel,
|
buttonLabel,
|
||||||
|
|
Loading…
Reference in New Issue