| Línea 20... |
Línea 20... |
| 20 |
* @copyright Catalyst IT
|
20 |
* @copyright Catalyst IT
|
| 21 |
* @author Alex Morris <alex.morris@catalyst.net.nz>
|
21 |
* @author Alex Morris <alex.morris@catalyst.net.nz>
|
| 22 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
22 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
| 23 |
*/
|
23 |
*/
|
| Línea -... |
Línea 24... |
| - |
|
24 |
|
| 24 |
|
25 |
define([
|
| - |
|
26 |
'factor_webauthn/utils',
|
| - |
|
27 |
'core/prefetch',
|
| - |
|
28 |
'core/str',
|
| - |
|
29 |
'core/toast',
|
| - |
|
30 |
], function(
|
| - |
|
31 |
utils,
|
| - |
|
32 |
Prefetch,
|
| - |
|
33 |
Str,
|
| - |
|
34 |
Toast,
|
| - |
|
35 |
) {
|
| 25 |
define(['factor_webauthn/utils', 'core/log'], function(utils, Log) {
|
36 |
|
| 26 |
/**
|
37 |
/**
|
| 27 |
* Register the security key.
|
38 |
* Register the security key.
|
| 28 |
*
|
39 |
*
|
| 29 |
* @param {*} createArgs
|
40 |
* @param {*} createArgs
|
| Línea 45... |
Línea 56... |
| 45 |
clientDataJSON: cred.response.clientDataJSON ?
|
56 |
clientDataJSON: cred.response.clientDataJSON ?
|
| 46 |
utils.arrayBufferToBase64(cred.response.clientDataJSON) : null,
|
57 |
utils.arrayBufferToBase64(cred.response.clientDataJSON) : null,
|
| 47 |
attestationObject: cred.response.attestationObject ?
|
58 |
attestationObject: cred.response.attestationObject ?
|
| 48 |
utils.arrayBufferToBase64(cred.response.attestationObject) : null,
|
59 |
utils.arrayBufferToBase64(cred.response.attestationObject) : null,
|
| 49 |
};
|
60 |
};
|
| - |
|
61 |
|
| - |
|
62 |
const registerSuccess = await Str.getString('registersuccess', 'factor_webauthn');
|
| - |
|
63 |
await Toast.add(registerSuccess, {type: 'success'});
|
| - |
|
64 |
|
| 50 |
document.getElementById('id_response_input').value = JSON.stringify(authenticatorResponse);
|
65 |
document.getElementById('id_response_input').value = JSON.stringify(authenticatorResponse);
|
| 51 |
// Enable the submit button so that we can proceed.
|
66 |
// Enable the submit button so that we can proceed.
|
| 52 |
document.getElementById('id_submitbutton').disabled = false;
|
67 |
document.getElementById('id_submitbutton').disabled = false;
|
| 53 |
} catch (e) {
|
68 |
} catch (e) {
|
| 54 |
Log.debug('The request timed out or you have canceled the request. Please try again later.');
|
69 |
const registerError = await Str.getString('registererror', 'factor_webauthn', e.message);
|
| - |
|
70 |
await Toast.add(registerError, {type: 'warning'});
|
| 55 |
}
|
71 |
}
|
| 56 |
}
|
72 |
}
|
| Línea 57... |
Línea 73... |
| 57 |
|
73 |
|
| 58 |
return {
|
74 |
return {
|
| 59 |
init: function(createArgs) {
|
75 |
init: function(createArgs) {
|
| 60 |
// Disable the submit button until we have registered a security key.
|
76 |
// Disable the submit button until we have registered a security key.
|
| - |
|
77 |
document.getElementById('id_submitbutton').disabled = true;
|
| 61 |
document.getElementById('id_submitbutton').disabled = true;
|
78 |
|
| - |
|
79 |
Prefetch.prefetchStrings('factor_webauthn', [
|
| - |
|
80 |
'registersuccess',
|
| - |
|
81 |
'registererror',
|
| - |
|
82 |
]);
|
| 62 |
createArgs = JSON.parse(createArgs);
|
83 |
|
| - |
|
84 |
// Register event listeners.
|
| 63 |
// Register event listeners.
|
85 |
createArgs = JSON.parse(createArgs);
|
| 64 |
document.getElementById('factor_webauthn-register').addEventListener('click', function() {
|
86 |
document.getElementById('factor_webauthn-register').addEventListener('click', function() {
|
| 65 |
registerSecurityKey(createArgs);
|
87 |
registerSecurityKey(createArgs);
|
| 66 |
});
|
88 |
});
|
| 67 |
document.getElementById('factor_webauthn-register').addEventListener('keypress', function() {
|
89 |
document.getElementById('factor_webauthn-register').addEventListener('keypress', function() {
|