mirror of
https://github.com/nocobase/nocobase
synced 2024-11-15 10:01:26 +00:00
fix(auth): sso auth bug when deploying with subpath (#3764)
This commit is contained in:
parent
a2ae4f7b70
commit
6a1be0fcd5
@ -3,20 +3,25 @@ import { AppSupervisor } from '@nocobase/server';
|
||||
import { CASAuth } from '../auth';
|
||||
|
||||
export const service = async (ctx: Context, next: Next) => {
|
||||
const { authenticator, __appName: appName, redirect = '/admin' } = ctx.action.params;
|
||||
const { authenticator, __appName: appName, redirect } = ctx.action.params;
|
||||
|
||||
let prefix = '';
|
||||
let prefix = process.env.APP_PUBLIC_PATH || '';
|
||||
if (appName && appName !== 'main') {
|
||||
const appSupervisor = AppSupervisor.getInstance();
|
||||
if (appSupervisor?.runningMode !== 'single') {
|
||||
prefix = process.env.APP_PUBLIC_PATH + `apps/${appName}`;
|
||||
prefix += `apps/${appName}`;
|
||||
}
|
||||
}
|
||||
|
||||
const auth = (await ctx.app.authManager.get(authenticator, ctx)) as CASAuth;
|
||||
|
||||
if (prefix.endsWith('/')) {
|
||||
prefix = prefix.slice(0, -1);
|
||||
}
|
||||
|
||||
try {
|
||||
const { token } = await auth.signIn();
|
||||
ctx.redirect(`${prefix}${redirect}?authenticator=${authenticator}&token=${token}`);
|
||||
ctx.redirect(`${prefix}${redirect || '/admin'}?authenticator=${authenticator}&token=${token}`);
|
||||
} catch (error) {
|
||||
ctx.redirect(`${prefix}/signin?authenticator=${authenticator}&error=${error.message}&redirect=${redirect}`);
|
||||
}
|
||||
|
@ -10,14 +10,17 @@ export const redirect = async (ctx: Context, next: Next) => {
|
||||
const authenticator = search.get('name');
|
||||
const appName = search.get('app');
|
||||
const redirect = search.get('redirect') || '/admin';
|
||||
let prefix = '';
|
||||
let prefix = process.env.APP_PUBLIC_PATH || '';
|
||||
if (appName && appName !== 'main') {
|
||||
const appSupervisor = AppSupervisor.getInstance();
|
||||
if (appSupervisor?.runningMode !== 'single') {
|
||||
prefix = process.env.APP_PUBLIC_PATH + `apps/${appName}`;
|
||||
prefix += `apps/${appName}`;
|
||||
}
|
||||
}
|
||||
const auth = (await ctx.app.authManager.get(authenticator, ctx)) as OIDCAuth;
|
||||
if (prefix.endsWith('/')) {
|
||||
prefix = prefix.slice(0, -1);
|
||||
}
|
||||
try {
|
||||
const { token } = await auth.signIn();
|
||||
ctx.redirect(`${prefix}${redirect}?authenticator=${authenticator}&token=${token}`);
|
||||
|
@ -4,18 +4,21 @@ import { SAMLAuth } from '../saml-auth';
|
||||
|
||||
export const redirect = async (ctx: Context, next: Next) => {
|
||||
const { authenticator, __appName: appName } = ctx.action.params || {};
|
||||
const { RelayState: redirect = '/admin' } = ctx.action.params.values || {};
|
||||
let prefix = '';
|
||||
const { RelayState: redirect } = ctx.action.params.values || {};
|
||||
let prefix = process.env.APP_PUBLIC_PATH || '';
|
||||
if (appName && appName !== 'main') {
|
||||
const appSupervisor = AppSupervisor.getInstance();
|
||||
if (appSupervisor?.runningMode !== 'single') {
|
||||
prefix = process.env.APP_PUBLIC_PATH + `apps/${appName}`;
|
||||
prefix += `/apps/${appName}`;
|
||||
}
|
||||
}
|
||||
const auth = (await ctx.app.authManager.get(authenticator, ctx)) as SAMLAuth;
|
||||
if (prefix.endsWith('/')) {
|
||||
prefix = prefix.slice(0, -1);
|
||||
}
|
||||
try {
|
||||
const { token } = await auth.signIn();
|
||||
ctx.redirect(`${prefix}${redirect}?authenticator=${authenticator}&token=${token}`);
|
||||
ctx.redirect(`${prefix}${redirect || '/admin'}?authenticator=${authenticator}&token=${token}`);
|
||||
} catch (error) {
|
||||
ctx.redirect(`${prefix}/signin?authenticator=${authenticator}&error=${error.message}&redirect=${redirect}`);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user