tachybase_todo/packages/plugins/saml/src/server/plugin.ts

50 lines
1.1 KiB
TypeScript
Raw Normal View History

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