2022-11-29 23:20:33 +08:00
|
|
|
import { InstallOptions, Plugin } from '@nocobase/server';
|
|
|
|
import { resolve } from 'path';
|
|
|
|
import { getAuthUrl } from './actions/getAuthUrl';
|
2022-11-30 01:00:45 +08:00
|
|
|
import { getEnabledProviders } from './actions/getEnabledProviders';
|
|
|
|
import { metadata } from './actions/metadata';
|
|
|
|
import { redirect } from './actions/redirect';
|
|
|
|
import { saml } from './authenticators/saml';
|
2022-11-29 23:20:33 +08:00
|
|
|
|
|
|
|
export class SAMLPlugin extends Plugin {
|
|
|
|
afterAdd() {}
|
|
|
|
|
|
|
|
beforeLoad() {}
|
|
|
|
|
|
|
|
async load() {
|
|
|
|
// 导入 collection
|
2023-01-08 20:47:00 +08:00
|
|
|
await this.importCollections(resolve(__dirname, './collections'));
|
2022-11-29 23:20:33 +08:00
|
|
|
|
|
|
|
// 获取 User 插件
|
2022-11-30 01:00:45 +08:00
|
|
|
const userPlugin = this.app.getPlugin<any>('users');
|
2022-11-29 23:20:33 +08:00
|
|
|
|
|
|
|
// 注册 SAML 验证器
|
|
|
|
userPlugin.authenticators.register('saml', saml);
|
|
|
|
|
|
|
|
// 注册接口
|
|
|
|
this.app.resource({
|
|
|
|
name: 'saml',
|
|
|
|
actions: {
|
|
|
|
redirect,
|
|
|
|
metadata,
|
|
|
|
getAuthUrl,
|
2022-11-30 01:00:45 +08:00
|
|
|
getEnabledProviders,
|
2022-11-29 23:20:33 +08:00
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
// 开放访问权限
|
2023-01-09 07:35:48 +08:00
|
|
|
this.app.acl.allow('saml', '*', 'public');
|
|
|
|
|
|
|
|
this.app.acl.registerSnippet({
|
|
|
|
name: `pm.${this.name}.providers`,
|
|
|
|
actions: ['samlProviders:*'],
|
|
|
|
});
|
2022-11-29 23:20:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
async install(options?: InstallOptions) {}
|
|
|
|
|
|
|
|
async afterEnable() {}
|
|
|
|
|
|
|
|
async afterDisable() {}
|
|
|
|
|
|
|
|
async remove() {}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default SAMLPlugin;
|