tachybase_todo/packages/plugins/@nocobase/plugin-oidc/src/server/plugin.ts
YANG QIA 89361ef61c
fix(auth): SSO issues (#2733)
* fix(auth): sso switch popup to rediect (fix T-2024)

* refactor: auth process optimization

* fix: test

* chore: add error handler

* fix(auth): sso redirection issue of sub app

* Revert "refactor(auth): OIDC, SAML auth switch popup to redirectction (#2737)"

This reverts commit beb4793051.

* Revert "Revert "refactor(auth): OIDC, SAML auth switch popup to redirectction (#2737)""

This reverts commit 301a85d767.

* refactor(oidc): improve validate logic

* refactor(saml): improve auth logic

* fix: test

* refactor(cas): improve auth logic

* chore: add error handler

* fix(oidc): subapp callback issue

* fix: add dependency

* chore: add dependency

* fix(auth): set default `userBindField:email`
2023-10-12 00:54:00 -05:00

64 lines
1.4 KiB
TypeScript

import { Gateway, InstallOptions, Plugin } from '@nocobase/server';
import { getAuthUrl } from './actions/getAuthUrl';
import { redirect } from './actions/redirect';
import { authType } from '../constants';
import { OIDCAuth } from './oidc-auth';
import { resolve } from 'path';
export class OidcPlugin extends Plugin {
afterAdd() {}
beforeLoad() {}
async load() {
this.db.addMigrations({
namespace: 'auth',
directory: resolve(__dirname, 'migrations'),
context: {
plugin: this,
},
});
this.app.authManager.registerTypes(authType, {
auth: OIDCAuth,
});
// 注册接口
this.app.resource({
name: 'oidc',
actions: {
getAuthUrl,
redirect,
},
});
this.app.acl.allow('oidc', '*', '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(options?: InstallOptions) {}
async afterEnable() {}
async afterDisable() {}
async remove() {}
}
export default OidcPlugin;