AutorÃa | Ultima modificación | Ver Log |
{"version":3,"file":"authorize.min.js","sources":["../../src/moodlenet/authorize.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 * MoodleNet authorization.\n *\n * @module core/moodlenet/authorize\n * @copyright 2023 Huong Nguyen <huongnv13@gmail.com>\n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n * @since
4.3\n */\n\nimport {alert as displayAlert, exception as displayException} from 'core/notification';\nimport * as MoodleNetService from 'core/moodlenet/service';\nimport {sendToMoodleNet} from 'core/moodlenet/send_resource';\n\n/**\n * Handle authorization with MoodleNet server.\n *\n * @param {int} issuerId The OAuth 2 issuer ID.\n * @param {int} courseId Course id.\n * @param {int} resourceId Resource id.\n * @param {int} shareFormat Share format.\n * @return {promise}\n */\nexport const handleAuthorization = (issuerId, courseId, resourceId, shareFormat) => {\n const windowSizeWidth = 550;\n const windowSizeHeight = 550;\n\n // Check if the user is authorized with MoodleNet or not.\n return MoodleNetService.authorizationCheck(issuerId, courseId).then(async(data) => {\n if (!data.status) {\n // Not yet authorized.\n // Declare moodleNetAuthorize variable, so we can call it later in the callback.\n window.moodleNetAuthorize = (error, errorDescription) =>
{\n // This will be called by the callback after the authorization is successful.\n if (error === '') {\n handleAuthorization(issuerId, courseId, resourceId, shareFormat);\n } else if (error !== 'access_denied') {\n displayAlert(\n 'Authorization error',\n 'Error: ' + error + '<br><br>Error description: ' + errorDescription,\n 'Cancel'\n );\n }\n };\n // Open the login url of the OAuth 2 issuer for user to login into MoodleNet and authorize.\n return window.open(data.loginurl, 'moodlenet_auth',\n `location=0,status=0,width=${windowSizeWidth},height=${windowSizeHeight},scrollbars=yes`);\n } else {\n // Already authorized.\n return sendToMoodleNet(issuerId, resourceId, shareFormat);\n }\n }).catch(displayException);\n};\n"],"names":["handleA
uthorization","issuerId","courseId","resourceId","shareFormat","MoodleNetService","authorizationCheck","then","async","data","status","window","moodleNetAuthorize","error","errorDescription","open","loginurl","catch","displayException"],"mappings":";;;;;;;;8BAqCaA,oBAAsB,CAACC,SAAUC,SAAUC,WAAYC,cAKzDC,iBAAiBC,mBAAmBL,SAAUC,UAAUK,MAAKC,MAAAA,MAC3DC,KAAKC,QAoBC,kCAAgBT,SAAUE,WAAYC,cAjB7CO,OAAOC,mBAAqB,CAACC,MAAOC,oBAElB,KAAVD,MACAb,oBAAoBC,SAAUC,SAAUC,WAAYC,aACnC,kBAAVS,+BAEH,sBACA,UAAYA,MAAQ,8BAAgCC,iBACpD,WAKLH,OAAOI,KAAKN,KAAKO,SAAU,qDArBlB,uBACC,2BA0BtBC,MAAMC"}