2024-07-18 12:34:49 +08:00
|
|
|
import { Gateway, Plugin } from '@tachybase/server';
|
|
|
|
|
2024-07-18 13:11:31 +08:00
|
|
|
import { authType } from '../constants';
|
2024-07-18 12:34:49 +08:00
|
|
|
import { getAuthUrl, redirect } from './actions/dingding';
|
2024-07-18 13:11:31 +08:00
|
|
|
import { DingtalkAuth } from './dingtalk-auth';
|
2024-07-18 12:34:49 +08:00
|
|
|
|
|
|
|
export class PluginDingdingServer extends Plugin {
|
|
|
|
async afterAdd() {}
|
|
|
|
|
|
|
|
async beforeLoad() {}
|
|
|
|
|
|
|
|
async load() {
|
|
|
|
this.app.authManager.registerTypes(authType, {
|
2024-07-18 13:11:31 +08:00
|
|
|
auth: DingtalkAuth,
|
2024-07-18 12:34:49 +08:00
|
|
|
});
|
|
|
|
this.app.resourcer.define({
|
|
|
|
name: 'dingtalk',
|
|
|
|
actions: {
|
|
|
|
getAuthUrl: getAuthUrl,
|
|
|
|
redirect: redirect,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
this.app.acl.allow('dingtalk', '*', 'public');
|
|
|
|
Gateway.getInstance().addAppSelectorMiddleware(async (ctx, next) => {
|
|
|
|
const { req } = ctx;
|
|
|
|
const url = new URL(req.url, `http://${req.headers.host}`);
|
|
|
|
const params = url.searchParams;
|
|
|
|
const state = params.get('state');
|
|
|
|
if (!state) {
|
|
|
|
return next();
|
|
|
|
}
|
|
|
|
const search = new URLSearchParams(state);
|
|
|
|
const appName = search.get('app');
|
|
|
|
if (appName) {
|
|
|
|
ctx.resolvedAppName = appName;
|
|
|
|
}
|
|
|
|
await next();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
async install() {}
|
|
|
|
|
|
|
|
async afterEnable() {}
|
|
|
|
|
|
|
|
async afterDisable() {}
|
|
|
|
|
|
|
|
async remove() {}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default PluginDingdingServer;
|