tachybase_todo/packages/plugins/@nocobase/plugin-oidc/src/server/actions/getAuthUrl.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

25 lines
764 B
TypeScript

import { Context, Next } from '@nocobase/actions';
import { OIDCAuth } from '../oidc-auth';
import { nanoid } from 'nanoid';
import { cookieName } from '../../constants';
export const getAuthUrl = async (ctx: Context, next: Next) => {
const app = ctx.app.name;
const auth = ctx.auth as OIDCAuth;
const client = await auth.createOIDCClient();
const { scope } = auth.getOptions();
const token = nanoid(15);
ctx.cookies.set(cookieName, token, {
httpOnly: true,
domain: ctx.hostname,
});
ctx.body = client.authorizationUrl({
response_type: 'code',
scope: scope || 'openid email profile',
redirect_uri: auth.getRedirectUri(),
state: `token=${token}&name=${ctx.headers['x-authenticator']}&app=${app}`,
});
return next();
};