This commit is contained in:
Huong Nguyen 2023-10-02 11:36:59 +07:00
commit 8b395dcfc3
No known key found for this signature in database
GPG Key ID: 40D88AB693A3E72A
3 changed files with 17 additions and 14 deletions

View File

@ -6,6 +6,6 @@
* @author Alex Morris <alex.morris@catalyst.net.nz>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
define("factor_webauthn/register",["factor_webauthn/utils"],(function(utils){return{init:function(createArgs){document.getElementById("factor_webauthn-register").addEventListener("click",(async function(e){if(e.preventDefault(),!navigator.credentials||!navigator.credentials.create)throw new Error("Browser not supported.");if(!1===(createArgs=JSON.parse(createArgs)).success)throw new Error(createArgs.msg||"unknown error occured");utils.recursiveBase64StrToArrayBuffer(createArgs);const cred=await navigator.credentials.create(createArgs),authenticatorResponse={transports:cred.response.getTransports?cred.response.getTransports():null,clientDataJSON:cred.response.clientDataJSON?utils.arrayBufferToBase64(cred.response.clientDataJSON):null,attestationObject:cred.response.attestationObject?utils.arrayBufferToBase64(cred.response.attestationObject):null};document.getElementById("id_response_input").value=JSON.stringify(authenticatorResponse)}))}}}));
define("factor_webauthn/register",["factor_webauthn/utils"],(function(utils){return{init:function(createArgs){createArgs=JSON.parse(createArgs),document.getElementById("factor_webauthn-register").addEventListener("click",(async function(e){if(e.preventDefault(),!navigator.credentials||!navigator.credentials.create)throw new Error("Browser not supported.");if(!1===createArgs.success)throw new Error(createArgs.msg||"unknown error occured");try{utils.recursiveBase64StrToArrayBuffer(createArgs);const cred=await navigator.credentials.create(createArgs),authenticatorResponse={transports:cred.response.getTransports?cred.response.getTransports():null,clientDataJSON:cred.response.clientDataJSON?utils.arrayBufferToBase64(cred.response.clientDataJSON):null,attestationObject:cred.response.attestationObject?utils.arrayBufferToBase64(cred.response.attestationObject):null};document.getElementById("id_response_input").value=JSON.stringify(authenticatorResponse)}catch(e){window.console.log("You canceled the process or it is timed out. Please try again.")}}))}}}));
//# sourceMappingURL=register.min.js.map

View File

@ -1 +1 @@
{"version":3,"file":"register.min.js","sources":["../src/register.js"],"sourcesContent":["// This file is part of Moodle - http://moodle.org/\n//\n// Moodle is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// Moodle is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with Moodle. If not, see <http://www.gnu.org/licenses/>.\n\n/**\n * For collecting WebAuthn authenticator details on factor setup\n *\n * @module factor_webauthn/register\n * @copyright Catalyst IT\n * @author Alex Morris <alex.morris@catalyst.net.nz>\n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\n\ndefine(['factor_webauthn/utils'], function(utils) {\n return {\n init: function(createArgs) {\n document.getElementById('factor_webauthn-register').addEventListener('click', async function(e) {\n e.preventDefault();\n if (!navigator.credentials || !navigator.credentials.create) {\n throw new Error('Browser not supported.');\n }\n\n createArgs = JSON.parse(createArgs);\n\n if (createArgs.success === false) {\n throw new Error(createArgs.msg || 'unknown error occured');\n }\n\n utils.recursiveBase64StrToArrayBuffer(createArgs);\n\n const cred = await navigator.credentials.create(createArgs);\n\n const authenticatorResponse = {\n transports: cred.response.getTransports ? cred.response.getTransports() : null,\n clientDataJSON: cred.response.clientDataJSON ? utils.arrayBufferToBase64(cred.response.clientDataJSON) : null,\n attestationObject:\n cred.response.attestationObject ? utils.arrayBufferToBase64(cred.response.attestationObject) : null\n };\n\n document.getElementById('id_response_input').value = JSON.stringify(authenticatorResponse);\n });\n }\n };\n});\n"],"names":["define","utils","init","createArgs","document","getElementById","addEventListener","async","e","preventDefault","navigator","credentials","create","Error","JSON","parse","success","msg","recursiveBase64StrToArrayBuffer","cred","authenticatorResponse","transports","response","getTransports","clientDataJSON","arrayBufferToBase64","attestationObject","value","stringify"],"mappings":";;;;;;;;AAwBAA,kCAAO,CAAC,0BAA0B,SAASC,aAChC,CACHC,KAAM,SAASC,YACXC,SAASC,eAAe,4BAA4BC,iBAAiB,SAASC,eAAeC,MACzFA,EAAEC,kBACGC,UAAUC,cAAgBD,UAAUC,YAAYC,aAC3C,IAAIC,MAAM,8BAKO,KAF3BV,WAAaW,KAAKC,MAAMZ,aAETa,cACL,IAAIH,MAAMV,WAAWc,KAAO,yBAGtChB,MAAMiB,gCAAgCf,kBAEhCgB,WAAaT,UAAUC,YAAYC,OAAOT,YAE1CiB,sBAAwB,CAC1BC,WAAYF,KAAKG,SAASC,cAAgBJ,KAAKG,SAASC,gBAAkB,KAC1EC,eAAgBL,KAAKG,SAASE,eAAiBvB,MAAMwB,oBAAoBN,KAAKG,SAASE,gBAAkB,KACzGE,kBACIP,KAAKG,SAASI,kBAAoBzB,MAAMwB,oBAAoBN,KAAKG,SAASI,mBAAqB,MAGvGtB,SAASC,eAAe,qBAAqBsB,MAAQb,KAAKc,UAAUR"}
{"version":3,"file":"register.min.js","sources":["../src/register.js"],"sourcesContent":["// This file is part of Moodle - http://moodle.org/\n//\n// Moodle is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// Moodle is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with Moodle. If not, see <http://www.gnu.org/licenses/>.\n\n/**\n * For collecting WebAuthn authenticator details on factor setup\n *\n * @module factor_webauthn/register\n * @copyright Catalyst IT\n * @author Alex Morris <alex.morris@catalyst.net.nz>\n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\n\ndefine(['factor_webauthn/utils'], function(utils) {\n return {\n init: function(createArgs) {\n createArgs = JSON.parse(createArgs);\n document.getElementById('factor_webauthn-register').addEventListener('click', async function(e) {\n e.preventDefault();\n if (!navigator.credentials || !navigator.credentials.create) {\n throw new Error('Browser not supported.');\n }\n\n if (createArgs.success === false) {\n throw new Error(createArgs.msg || 'unknown error occured');\n }\n\n try {\n utils.recursiveBase64StrToArrayBuffer(createArgs);\n const cred = await navigator.credentials.create(createArgs);\n\n const authenticatorResponse = {\n transports: cred.response.getTransports ? cred.response.getTransports() : null,\n clientDataJSON: cred.response.clientDataJSON ?\n utils.arrayBufferToBase64(cred.response.clientDataJSON) : null,\n attestationObject:\n cred.response.attestationObject ? utils.arrayBufferToBase64(cred.response.attestationObject) : null\n };\n\n document.getElementById('id_response_input').value = JSON.stringify(authenticatorResponse);\n } catch (e) {\n window.console.log('You canceled the process or it is timed out. Please try again.');\n }\n });\n }\n };\n});\n"],"names":["define","utils","init","createArgs","JSON","parse","document","getElementById","addEventListener","async","e","preventDefault","navigator","credentials","create","Error","success","msg","recursiveBase64StrToArrayBuffer","cred","authenticatorResponse","transports","response","getTransports","clientDataJSON","arrayBufferToBase64","attestationObject","value","stringify","window","console","log"],"mappings":";;;;;;;;AAwBAA,kCAAO,CAAC,0BAA0B,SAASC,aAChC,CACHC,KAAM,SAASC,YACXA,WAAaC,KAAKC,MAAMF,YACxBG,SAASC,eAAe,4BAA4BC,iBAAiB,SAASC,eAAeC,MACzFA,EAAEC,kBACGC,UAAUC,cAAgBD,UAAUC,YAAYC,aAC3C,IAAIC,MAAM,8BAGO,IAAvBZ,WAAWa,cACL,IAAID,MAAMZ,WAAWc,KAAO,6BAIlChB,MAAMiB,gCAAgCf,kBAChCgB,WAAaP,UAAUC,YAAYC,OAAOX,YAE1CiB,sBAAwB,CAC1BC,WAAYF,KAAKG,SAASC,cAAgBJ,KAAKG,SAASC,gBAAkB,KAC1EC,eAAgBL,KAAKG,SAASE,eAC1BvB,MAAMwB,oBAAoBN,KAAKG,SAASE,gBAAkB,KAC9DE,kBACIP,KAAKG,SAASI,kBAAoBzB,MAAMwB,oBAAoBN,KAAKG,SAASI,mBAAqB,MAGvGpB,SAASC,eAAe,qBAAqBoB,MAAQvB,KAAKwB,UAAUR,uBACtE,MAAOV,GACLmB,OAAOC,QAAQC,IAAI"}

View File

@ -25,30 +25,33 @@
define(['factor_webauthn/utils'], function(utils) {
return {
init: function(createArgs) {
createArgs = JSON.parse(createArgs);
document.getElementById('factor_webauthn-register').addEventListener('click', async function(e) {
e.preventDefault();
if (!navigator.credentials || !navigator.credentials.create) {
throw new Error('Browser not supported.');
}
createArgs = JSON.parse(createArgs);
if (createArgs.success === false) {
throw new Error(createArgs.msg || 'unknown error occured');
}
utils.recursiveBase64StrToArrayBuffer(createArgs);
try {
utils.recursiveBase64StrToArrayBuffer(createArgs);
const cred = await navigator.credentials.create(createArgs);
const cred = await navigator.credentials.create(createArgs);
const authenticatorResponse = {
transports: cred.response.getTransports ? cred.response.getTransports() : null,
clientDataJSON: cred.response.clientDataJSON ?
utils.arrayBufferToBase64(cred.response.clientDataJSON) : null,
attestationObject:
cred.response.attestationObject ? utils.arrayBufferToBase64(cred.response.attestationObject) : null
};
const authenticatorResponse = {
transports: cred.response.getTransports ? cred.response.getTransports() : null,
clientDataJSON: cred.response.clientDataJSON ? utils.arrayBufferToBase64(cred.response.clientDataJSON) : null,
attestationObject:
cred.response.attestationObject ? utils.arrayBufferToBase64(cred.response.attestationObject) : null
};
document.getElementById('id_response_input').value = JSON.stringify(authenticatorResponse);
document.getElementById('id_response_input').value = JSON.stringify(authenticatorResponse);
} catch (e) {
window.console.log('You canceled the process or it is timed out. Please try again.');
}
});
}
};