Proyectos de Subversion Moodle

Rev

Rev 1 | | Comparar con el anterior | Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1441 ariadna 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([\n    'factor_webauthn/utils',\n    'core/prefetch',\n    'core/str',\n    'core/toast',\n], function(\n    utils,\n    Prefetch,\n    Str,\n    Toast,\n) {\n\n    /**\n     * Register the security key.\n     *\n     * @param {*} createArgs\n     */\n    async function registerSecurityKey(createArgs) {\n        try {\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 occurred');\n            }\n\n            utils.recursiveBase64StrToArrayBuffer(createArgs);\n            const cred = await navigator.credentials.create(createArgs);\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: cred.response.attestationObject ?\n                    utils.arrayBufferToBase64(cred.response.attestationObject) : null,\n            };\n\n            const registerSuccess = await Str.getString('registersuccess', 'factor_webauthn');\n            await Toast.add(registerSuccess, {type: 'success'});\n\n            document.getElementById('id_response_input').value = JSON.stringify(authenticatorResponse);\n            // Enable the submit button so that we can proceed.\n            document.getElementById('id_submitbutton').disabled = false;\n        } catch (e) {\n            const registerError = await Str.getString('registererror', 'factor_webauthn', e.message);\n            await Toast.add(registerError, {type: 'warning'});\n        }\n    }\n\n    return {\n        init: function(createArgs) {\n            // Disable the submit button until we have registered a security key.\n            document.getElementById('id_submitbutton').disabled = true;\n\n            Prefetch.prefetchStrings('factor_webauthn', [\n                'registersuccess',\n                'registererror',\n            ]);\n\n            // Register event listeners.\n            createArgs = JSON.parse(createArgs);\n            document.getElementById('factor_webauthn-register').addEventListener('click', function() {\n                registerSecurityKey(createArgs);\n            });\n            document.getElementById('factor_webauthn-register').addEventListener('keypress', function() {\n                registerSecurityKey(createArgs);\n            });\n        }\n    };\n});\n"],"names":["define","utils","Prefetch","Str","Toast","registerSecurityKey","createArgs","navigator","credentials","create","Error","success","msg","recursiveBase64StrToArrayBuffer","cred","authenticatorResponse","transports","response","getTransports","clientDataJSON","arrayBufferToBase64","attestationObject","registerSuccess","getString","add","type","document","getElementById","value","JSON","stringify","disabled","e","registerError","message","init","prefetchStrings","parse","addEventListener"],"mappings":";;;;;;;;AAwBAA,kCAAO,CACH,wBACA,gBACA,WACA,eACD,SACCC,MACAC,SACAC,IACAC,sBAQeC,oBAAoBC,oBAEtBC,UAAUC,cAAgBD,UAAUC,YAAYC,aAC3C,IAAIC,MAAM,8BAGO,IAAvBJ,WAAWK,cACL,IAAID,MAAMJ,WAAWM,KAAO,0BAGtCX,MAAMY,gCAAgCP,kBAChCQ,WAAaP,UAAUC,YAAYC,OAAOH,YAC1CS,sBAAwB,CAC1BC,WAAYF,KAAKG,SAASC,cAAgBJ,KAAKG,SAASC,gBAAkB,KAC1EC,eAAgBL,KAAKG,SAASE,eAC1BlB,MAAMmB,oBAAoBN,KAAKG,SAASE,gBAAkB,KAC9DE,kBAAmBP,KAAKG,SAASI,kBAC7BpB,MAAMmB,oBAAoBN,KAAKG,SAASI,mBAAqB,MAG/DC,sBAAwBnB,IAAIoB,UAAU,kBAAmB,yBACzDnB,MAAMoB,IAAIF,gBAAiB,CAACG,KAAM,YAExCC,SAASC,eAAe,qBAAqBC,MAAQC,KAAKC,UAAUf,uBAEpEW,SAASC,eAAe,mBAAmBI,UAAW,EACxD,MAAOC,SACCC,oBAAsB9B,IAAIoB,UAAU,gBAAiB,kBAAmBS,EAAEE,eAC1E9B,MAAMoB,IAAIS,cAAe,CAACR,KAAM,mBAIvC,CACHU,KAAM,SAAS7B,YAEXoB,SAASC,eAAe,mBAAmBI,UAAW,EAEtD7B,SAASkC,gBAAgB,kBAAmB,CACxC,kBACA,kBAIJ9B,WAAauB,KAAKQ,MAAM/B,YACxBoB,SAASC,eAAe,4BAA4BW,iBAAiB,SAAS,WAC1EjC,oBAAoBC,eAExBoB,SAASC,eAAe,4BAA4BW,iBAAiB,YAAY,WAC7EjC,oBAAoBC"}