UNPKG

nocobase-plugin-casdoor

Version:

Integrated Casdoor authentication system

10 lines (9 loc) 9.28 kB
/** * This file is part of the NocoBase (R) project. * Copyright (c) 2020-2024 NocoBase Co., Ltd. * Authors: NocoBase Team. * * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License. * For more information, please refer to: https://www.nocobase.com/agreement. */ !function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e(require("react"),require("@nocobase/plugin-auth/client"),require("@nocobase/client"),require("antd")):"function"==typeof define&&define.amd?define("nocobase-plugin-casdoor",["react","@nocobase/plugin-auth/client","@nocobase/client","antd"],e):"object"==typeof exports?exports["nocobase-plugin-casdoor"]=e(require("react"),require("@nocobase/plugin-auth/client"),require("@nocobase/client"),require("antd")):t["nocobase-plugin-casdoor"]=e(t.react,t["@nocobase/plugin-auth/client"],t["@nocobase/client"],t.antd)}(self,function(t,e,n,r){return function(){"use strict";var o={772:function(t){t.exports=n},689:function(t){t.exports=e},721:function(t){t.exports=r},156:function(e){e.exports=t}},u={};function i(t){var e=u[t];if(void 0!==e)return e.exports;var n=u[t]={exports:{}};return o[t](n,n.exports,i),n.exports}i.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return i.d(e,{a:e}),e},i.d=function(t,e){for(var n in e)i.o(e,n)&&!i.o(t,n)&&Object.defineProperty(t,n,{enumerable:!0,get:e[n]})},i.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},i.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})};var a={};return!function(){i.r(a),i.d(a,{CasdoorPluginClient:function(){return w},default:function(){return S}});var t=i(772),e=i(689),n=i.n(e),r=i(156),o=i.n(r),u=i(721);function c(t,e){(null==e||e>t.length)&&(e=t.length);for(var n=0,r=Array(e);n<e;n++)r[n]=t[n];return r}function l(t,e,n,r,o,u,i){try{var a=t[u](i),c=a.value}catch(t){n(t);return}a.done?e(c):Promise.resolve(c).then(r,o)}var f=function(e){var n,i,a,f=(n=(0,r.useState)(!1),function(t){if(Array.isArray(t))return t}(n)||function(t,e){var n,r,o=null==t?null:"undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(null!=o){var u=[],i=!0,a=!1;try{for(o=o.call(t);!(i=(n=o.next()).done)&&(u.push(n.value),u.length!==e);i=!0);}catch(t){a=!0,r=t}finally{try{i||null==o.return||o.return()}finally{if(a)throw r}}return u}}(n,2)||function(t,e){if(t){if("string"==typeof t)return c(t,2);var n=Object.prototype.toString.call(t).slice(8,-1);if("Object"===n&&t.constructor&&(n=t.constructor.name),"Map"===n||"Set"===n)return Array.from(n);if("Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return c(t,e)}}(n,2)||function(){throw TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()),s=f[0],p=f[1],y=(0,t.useResource)("casdoor"),b=(i=function(){var t;return function(t,e){var n,r,o,u,i={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return u={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(u[Symbol.iterator]=function(){return this}),u;function a(u){return function(a){var c=[u,a];if(n)throw TypeError("Generator is already executing.");for(;i;)try{if(n=1,r&&(o=2&c[0]?r.return:c[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,c[1])).done)return o;switch(r=0,o&&(c=[2&c[0],o.value]),c[0]){case 0:case 1:o=c;break;case 4:return i.label++,{value:c[1],done:!1};case 5:i.label++,r=c[1],c=[0];continue;case 7:c=i.ops.pop(),i.trys.pop();continue;default:if(!(o=(o=i.trys).length>0&&o[o.length-1])&&(6===c[0]||2===c[0])){i=0;continue}if(3===c[0]&&(!o||c[1]>o[0]&&c[1]<o[3])){i.label=c[1];break}if(6===c[0]&&i.label<o[1]){i.label=o[1],o=c;break}if(o&&i.label<o[2]){i.label=o[2],i.ops.push(c);break}o[2]&&i.ops.pop(),i.trys.pop();continue}c=e.call(t,i)}catch(t){c=[6,t],r=0}finally{n=o=0}if(5&c[0])throw c[1];return{value:c[0]?c[1]:void 0,done:!0}}}}(this,function(n){switch(n.label){case 0:p(!0),n.label=1;case 1:return n.trys.push([1,,3,4]),[4,y.getAuthUrl({values:{authenticator:e.authenticator.name,redirect:new URLSearchParams(location.search?location.search.substring(1):"").get("redirect")||""}})];case 2:return t=n.sent(),location.href=t.data.data,[3,4];case 3:return setTimeout(function(){p(!1)},1e3),[7];case 4:return[2]}})},a=function(){var t=this,e=arguments;return new Promise(function(n,r){var o=i.apply(t,e);function u(t){l(o,n,r,u,a,"next",t)}function a(t){l(o,n,r,u,a,"throw",t)}u(void 0)})},function(){return a.apply(this,arguments)});return o().createElement(u.Button,{loading:s,disabled:s,style:{width:"100%"},onClick:b},e.authenticator.title||e.authenticator.name)},s=function(){return o().createElement(t.SchemaComponent,{schema:{type:"object",properties:{communityDingTalkAuth:{type:"void",properties:{public:{type:"object",properties:{autoSignup:{"x-decorator":"FormItem",type:"boolean",title:"用户不存在时自动注册",required:!1,"x-component":"Checkbox"}}},internal:{type:"object",properties:{emailDomain:{"x-decorator":"FormItem",type:"string",title:"邮箱域名,多个使用英文逗号分隔",required:!0,"x-component":"Input"},endpoint:{"x-decorator":"FormItem",type:"string",title:"地址",required:!0,"x-component":"Input"},clientId:{"x-decorator":"FormItem",type:"string",title:"应用ID",required:!0,"x-component":"Input"},clientSecret:{"x-decorator":"FormItem",type:"string",title:"应用秘钥",required:!0,"x-component":"Password"}}}}}}}})},p="".concat("casdoor","-auth");function y(t,e,n,r,o,u,i){try{var a=t[u](i),c=a.value}catch(t){n(t);return}a.done?e(c):Promise.resolve(c).then(r,o)}function b(t){return function(){var e=this,n=arguments;return new Promise(function(r,o){var u=t.apply(e,n);function i(t){y(u,r,o,i,a,"next",t)}function a(t){y(u,r,o,i,a,"throw",t)}i(void 0)})}}function d(t,e,n){return(d=g()?Reflect.construct:function(t,e,n){var r=[null];r.push.apply(r,e);var o=new(Function.bind.apply(t,r));return n&&v(o,n.prototype),o}).apply(null,arguments)}function h(t){return(h=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)})(t)}function v(t,e){return(v=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t})(t,e)}function m(t){var e="function"==typeof Map?new Map:void 0;return(m=function(t){if(null===t||-1===Function.toString.call(t).indexOf("[native code]"))return t;if("function"!=typeof t)throw TypeError("Super expression must either be null or a function");if(void 0!==e){if(e.has(t))return e.get(t);e.set(t,n)}function n(){return d(t,arguments,h(this).constructor)}return n.prototype=Object.create(t.prototype,{constructor:{value:n,enumerable:!1,writable:!0,configurable:!0}}),v(n,t)})(t)}function g(){try{var t=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(t){}return(g=function(){return!!t})()}function x(t,e){var n,r,o,u,i={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return u={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(u[Symbol.iterator]=function(){return this}),u;function a(u){return function(a){var c=[u,a];if(n)throw TypeError("Generator is already executing.");for(;i;)try{if(n=1,r&&(o=2&c[0]?r.return:c[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,c[1])).done)return o;switch(r=0,o&&(c=[2&c[0],o.value]),c[0]){case 0:case 1:o=c;break;case 4:return i.label++,{value:c[1],done:!1};case 5:i.label++,r=c[1],c=[0];continue;case 7:c=i.ops.pop(),i.trys.pop();continue;default:if(!(o=(o=i.trys).length>0&&o[o.length-1])&&(6===c[0]||2===c[0])){i=0;continue}if(3===c[0]&&(!o||c[1]>o[0]&&c[1]<o[3])){i.label=c[1];break}if(6===c[0]&&i.label<o[1]){i.label=o[1],o=c;break}if(o&&i.label<o[2]){i.label=o[2],i.ops.push(c);break}o[2]&&i.ops.pop(),i.trys.pop();continue}c=e.call(t,i)}catch(t){c=[6,t],r=0}finally{n=o=0}if(5&c[0])throw c[1];return{value:c[0]?c[1]:void 0,done:!0}}}}var w=function(t){var e;if("function"!=typeof t&&null!==t)throw TypeError("Super expression must either be null or a function");function r(){var t,e;if(!(this instanceof r))throw TypeError("Cannot call a class as a function");return t=r,e=arguments,t=h(t),function(t,e){var n;if(e&&("object"==((n=e)&&"undefined"!=typeof Symbol&&n.constructor===Symbol?"symbol":typeof n)||"function"==typeof e))return e;if(void 0===t)throw ReferenceError("this hasn't been initialised - super() hasn't been called");return t}(this,g()?Reflect.construct(t,e||[],h(this).constructor):t.apply(this,e))}return r.prototype=Object.create(t&&t.prototype,{constructor:{value:r,writable:!0,configurable:!0}}),t&&v(r,t),e=[{key:"afterAdd",value:function(){return b(function(){return x(this,function(t){return[2]})})()}},{key:"beforeLoad",value:function(){return b(function(){return x(this,function(t){return[2]})})()}},{key:"load",value:function(){var t=this;return b(function(){return x(this,function(e){return t.app.pm.get(n()).registerType(p,{components:{SignInButton:f,AdminSettingsForm:s}}),[2]})})()}}],function(t,e){for(var n=0;n<e.length;n++){var r=e[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,r.key,r)}}(r.prototype,e),r}(m(t.Plugin)),S=w}(),a}()});