feat(auth): 重构统一认证并支持平级服务无感登录
This commit is contained in:
1 parent
d79def5519
commit
ca312ea751
64 files changed
+3713
-449
No files matched your search
@@ -62,7 +62,10 @@ watch(themePreference, (newTheme) => {
|
||||
updateThemePreference(newTheme);
|
||||
});
|
||||
|
||||
const onUnauthorized = () => {
|
||||
const onUnauthorized = (event: Event) => {
|
||||
const url = String((event as CustomEvent<{ url?: string }>).detail?.url || '');
|
||||
// 外部应用目录是可选导航能力,加载失败只能隐藏入口,不能清除有效 HXOPS 登录态。
|
||||
if (/\/api\/sso\/apps(?:\?|$)/.test(url)) return;
|
||||
showMessageDialog('error', '认证已过期或无效,请重新登录');
|
||||
logoutAuth();
|
||||
};
|
||||
|
||||
@@ -5,9 +5,13 @@
|
||||
import type { RouteRecordRaw } from 'vue-router';
|
||||
import LoginView from '@/features/auth/views/LoginView.vue';
|
||||
import ResetPasswordView from '@/features/auth/views/ResetPasswordView.vue';
|
||||
import SsoAuthorizeView from '@/features/sso/views/SsoAuthorizeView.vue';
|
||||
import SsoLaunchView from '@/features/sso/views/SsoLaunchView.vue';
|
||||
|
||||
export const authRoutes: RouteRecordRaw[] = [
|
||||
{ path: '/login', name: 'Login', component: LoginView },
|
||||
{ path: '/casdoor-callback', name: 'CasdoorCallback', component: LoginView },
|
||||
{ path: '/reset-password', name: 'ResetPassword', component: ResetPasswordView },
|
||||
{ path: '/sso/authorize', name: 'SsoAuthorize', component: SsoAuthorizeView },
|
||||
{ path: '/sso/launch', name: 'SsoLaunch', component: SsoLaunchView },
|
||||
];
|
||||
@@ -4,7 +4,7 @@ export const config = {
|
||||
// Login mode switch:
|
||||
// - 'casdoor': submit username/password to backend Casdoor password-login API.
|
||||
// - 'password': submit to legacy local /api/user/login.
|
||||
loginMode: 'password',
|
||||
loginMode: 'casdoor',
|
||||
casdoor: {
|
||||
enabled: true,
|
||||
authorizeApi: '/api/user/casdoor/authorize-url',
|
||||
|
||||
@@ -12,6 +12,7 @@ import { useAuthStore } from '@/features/auth/stores/auth.store';
|
||||
import loginBg from '@/assets/login-bg.png';
|
||||
import { DEFAULT_POST_LOGIN_AGENT_ID } from '@/features/workspace/types/workspace.types';
|
||||
import { useWorkspaceLocale } from '@/features/workspace/composables/useWorkspaceLocale';
|
||||
import { continuationLocation, readSsoContinuation } from '@/features/sso';
|
||||
import { useLoginAuth } from './useLoginAuth';
|
||||
import { useLoginLanding } from './useLoginLanding';
|
||||
|
||||
@@ -28,11 +29,21 @@ export function useLogin() {
|
||||
|
||||
const completePasswordLogin = async () => {
|
||||
authStore.syncFromStorage();
|
||||
const continuation = readSsoContinuation();
|
||||
if (continuation) {
|
||||
await router.replace(continuationLocation(continuation));
|
||||
return;
|
||||
}
|
||||
await router.replace(`/chat/${DEFAULT_POST_LOGIN_AGENT_ID}`);
|
||||
};
|
||||
|
||||
const completeOAuthLogin = async () => {
|
||||
authStore.syncFromStorage();
|
||||
const continuation = readSsoContinuation();
|
||||
if (continuation) {
|
||||
await router.replace(continuationLocation(continuation));
|
||||
return;
|
||||
}
|
||||
await router.replace('/workspace/applications');
|
||||
};
|
||||
|
||||
@@ -58,7 +69,8 @@ export function useLogin() {
|
||||
|
||||
authStore.syncFromStorage();
|
||||
if (authStore.isLoggedIn) {
|
||||
await router.replace('/workspace/applications');
|
||||
const continuation = readSsoContinuation();
|
||||
await router.replace(continuation ? continuationLocation(continuation) : '/workspace/applications');
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
import { onBeforeUnmount, onMounted, ref } from 'vue';
|
||||
import { BookOpen, History, LayoutGrid } from 'lucide-vue-next';
|
||||
import AgentCategoryList from '@/shared/components/AgentCategoryList.vue';
|
||||
import { ExternalSystemLinks } from '@/features/sso';
|
||||
import type { AgentWithCategory } from '@/shared/utils/agent-category.utils';
|
||||
|
||||
export interface ChatMobileHeaderAgent extends AgentWithCategory {}
|
||||
@@ -76,6 +77,7 @@ onBeforeUnmount(() => {
|
||||
</button>
|
||||
</div>
|
||||
<div class="flex items-center gap-1">
|
||||
<ExternalSystemLinks compact :show-label="false" />
|
||||
<button
|
||||
type="button"
|
||||
class="flex h-9 w-9 items-center justify-center rounded-full text-muted transition-colors hover-surface-soft"
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/**
|
||||
* features/chat/components/ChatSidebar.vue
|
||||
* 用途:桌面端聊天侧栏,承载 Agent 信息、会话历史、Agent 切换面板与底部用户菜单。
|
||||
* 依赖:lucide-vue-next、LocaleToggleButton、AgentCategoryList、chat.types。
|
||||
* 依赖:lucide-vue-next、LocaleToggleButton、ExternalSystemLinks、AgentCategoryList、chat.types。
|
||||
* 逻辑:由聊天页面传入当前 Agent、历史记录与用户可用 Agent;通过事件把新会话、切换 Agent、反馈、进入管理控制台等操作回传给页面。
|
||||
* 管理员通过底部右侧工具图标进入管理控制台;用户下拉菜单仅保留退出登录。
|
||||
*/
|
||||
@@ -25,6 +25,7 @@ import {
|
||||
X,
|
||||
} from 'lucide-vue-next';
|
||||
import LocaleToggleButton from '@/shared/components/LocaleToggleButton.vue';
|
||||
import { ExternalSystemLinks } from '@/features/sso';
|
||||
import AgentCategoryList from '@/shared/components/AgentCategoryList.vue';
|
||||
import { isHrFocusedAgent, type AgentRegistryFields } from '@/shared/utils/agent-registry.utils';
|
||||
import type { AgentWithCategory } from '@/shared/utils/agent-category.utils';
|
||||
@@ -128,6 +129,7 @@ const userInitial = (fallback: string) => {
|
||||
</button>
|
||||
|
||||
<div class="mt-auto flex flex-col items-center gap-6 pb-2 text-muted">
|
||||
<ExternalSystemLinks compact :show-label="false" />
|
||||
<button type="button" class="transition-colors hover:text-secondary"><Sparkles class="h-5 w-5" /></button>
|
||||
<div class="flex h-8 w-8 items-center justify-center rounded-full bg-brand-600 text-sm font-bold text-white shadow-sm shadow-brand-500/20">
|
||||
{{ userInitial('I') }}
|
||||
@@ -301,6 +303,7 @@ const userInitial = (fallback: string) => {
|
||||
</div>
|
||||
|
||||
<div class="flex gap-3">
|
||||
<ExternalSystemLinks compact :show-label="false" />
|
||||
<button
|
||||
type="button"
|
||||
class="transition-colors hover:text-secondary"
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
/**
|
||||
* features/sso/api/sso.api.ts
|
||||
* 用途:访问 HXOPS 平级服务目录与短时登录 assertion 签发接口。
|
||||
* 依赖:shared/api/client。
|
||||
* 逻辑:导航组件读取安全服务元数据;授权页按 app key 请求受众绑定 JWT 和服务端登记的回调地址。
|
||||
*/
|
||||
import { requestJson } from '@/shared/api/client';
|
||||
|
||||
export interface SsoApplication {
|
||||
key: string;
|
||||
display_name: string;
|
||||
login_url: string;
|
||||
}
|
||||
|
||||
export interface SsoAssertionResponse {
|
||||
post_url: string;
|
||||
assertion: string;
|
||||
state: string;
|
||||
expires_in: number;
|
||||
}
|
||||
|
||||
/** 获取当前用户可见的已启用产品内平级服务。 */
|
||||
export async function listSsoApplications(): Promise<SsoApplication[]> {
|
||||
const data = await requestJson<{ items?: SsoApplication[] }>('/api/sso/apps');
|
||||
return Array.isArray(data?.items) ? data.items : [];
|
||||
}
|
||||
|
||||
/**
|
||||
* 为目标平级服务签发受众绑定的短时登录 assertion。
|
||||
* @param appKey - 服务端配置的应用 key,不能传 callback URL。
|
||||
* @param state - 平级服务签名的短时 state,HXOPS 仅原样返回。
|
||||
*/
|
||||
export function createSsoAssertion(appKey: string, state: string): Promise<SsoAssertionResponse> {
|
||||
return requestJson<SsoAssertionResponse>(`/api/sso/apps/${encodeURIComponent(appKey)}/assertions`, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ state }),
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
<!--
|
||||
features/sso/components/ExternalSystemLinks.vue
|
||||
用途:在 HXOPS 已登录页面展示已配置产品内平级服务入口。
|
||||
依赖:SSO 应用目录 API、lucide-vue-next。
|
||||
逻辑:点击后先打开 HXOPS 同源 launch 页以继承当前登录态,再由 launch 页跳平级服务生成签名 state。
|
||||
-->
|
||||
<script setup lang="ts">
|
||||
import { onMounted, ref } from 'vue';
|
||||
import { ExternalLink } from 'lucide-vue-next';
|
||||
import { listSsoApplications, type SsoApplication } from '../api/sso.api';
|
||||
|
||||
withDefaults(defineProps<{
|
||||
compact?: boolean;
|
||||
showLabel?: boolean;
|
||||
}>(), {
|
||||
compact: false,
|
||||
showLabel: true,
|
||||
});
|
||||
|
||||
const applications = ref<SsoApplication[]>([]);
|
||||
|
||||
/** 加载已启用应用;目录不可用时隐藏入口,不阻断 HXOPS 主业务。 */
|
||||
async function loadApplications(): Promise<void> {
|
||||
try {
|
||||
applications.value = await listSsoApplications();
|
||||
} catch (error) {
|
||||
console.warn('[sso] failed to load peer services', error);
|
||||
}
|
||||
}
|
||||
|
||||
/** 在新标签先打开同源中转页,确保非 remember 登录态也可继承到新标签。 */
|
||||
function openApplication(application: SsoApplication): void {
|
||||
window.open(`/sso/launch?app=${encodeURIComponent(application.key)}`, '_blank');
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
void loadApplications();
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<template v-for="application in applications" :key="application.key">
|
||||
<button
|
||||
type="button"
|
||||
class="inline-flex items-center justify-center gap-2 rounded-xl text-muted transition-colors hover:bg-surface-soft hover:text-secondary"
|
||||
:class="compact ? 'h-9 w-9' : 'min-h-9 px-3 py-2 text-sm'"
|
||||
:title="application.display_name"
|
||||
@click="openApplication(application)"
|
||||
>
|
||||
<ExternalLink class="h-4 w-4 shrink-0" />
|
||||
<span v-if="showLabel && !compact" class="truncate">{{ application.display_name }}</span>
|
||||
</button>
|
||||
</template>
|
||||
</template>
|
||||
@@ -0,0 +1,11 @@
|
||||
/**
|
||||
* features/sso/index.ts
|
||||
* 用途:统一导出 SSO 复用组件与续跳能力。
|
||||
* 依赖:features/sso 子模块。
|
||||
* 逻辑:页面通过本入口复用平级服务导航,登录模块复用 continuation。
|
||||
*/
|
||||
export { default as ExternalSystemLinks } from './components/ExternalSystemLinks.vue';
|
||||
export {
|
||||
continuationLocation,
|
||||
readSsoContinuation,
|
||||
} from './utils/continuation';
|
||||
@@ -0,0 +1,72 @@
|
||||
/**
|
||||
* features/sso/utils/continuation.ts
|
||||
* 用途:在平级服务跳转到 HXOPS 登录页期间保存并恢复 SSO 请求。
|
||||
* 依赖:浏览器 sessionStorage、Vue Router 查询参数类型。
|
||||
* 逻辑:只保存 app key 和签名 state,不接收或持久化 callback URL、JWT 或用户资料。
|
||||
*/
|
||||
import type { LocationQuery } from 'vue-router';
|
||||
|
||||
export interface SsoContinuation {
|
||||
app: string;
|
||||
state: string;
|
||||
createdAt: number;
|
||||
}
|
||||
|
||||
const STORAGE_KEY = 'hxops_sso_continuation';
|
||||
const MAX_AGE_MS = 10 * 60 * 1000;
|
||||
const APP_KEY_PATTERN = /^[a-z0-9][a-z0-9_-]{1,63}$/;
|
||||
|
||||
/** 从授权路由查询参数构造安全的续跳请求。 */
|
||||
export function parseSsoContinuation(query: LocationQuery): SsoContinuation | null {
|
||||
const app = typeof query.app === 'string' ? query.app.trim().toLowerCase() : '';
|
||||
const state = typeof query.state === 'string' ? query.state.trim() : '';
|
||||
if (!APP_KEY_PATTERN.test(app) || !state || state.length > 4096) return null;
|
||||
return { app, state, createdAt: Date.now() };
|
||||
}
|
||||
|
||||
/** 保存未登录用户的 SSO 请求,登录成功后在同一标签页恢复。 */
|
||||
export function saveSsoContinuation(continuation: SsoContinuation): void {
|
||||
sessionStorage.setItem(STORAGE_KEY, JSON.stringify(continuation));
|
||||
}
|
||||
|
||||
/** 读取仍在有效期内的 SSO 请求;坏数据或超时数据会立即清理。 */
|
||||
export function readSsoContinuation(): SsoContinuation | null {
|
||||
try {
|
||||
const raw = sessionStorage.getItem(STORAGE_KEY);
|
||||
if (!raw) return null;
|
||||
const data = JSON.parse(raw) as Partial<SsoContinuation>;
|
||||
if (
|
||||
!APP_KEY_PATTERN.test(String(data.app || ''))
|
||||
|| !String(data.state || '')
|
||||
|| String(data.state || '').length > 4096
|
||||
|| Date.now() - Number(data.createdAt || 0) > MAX_AGE_MS
|
||||
) {
|
||||
clearSsoContinuation();
|
||||
return null;
|
||||
}
|
||||
return {
|
||||
app: String(data.app),
|
||||
state: String(data.state),
|
||||
createdAt: Number(data.createdAt),
|
||||
};
|
||||
} catch {
|
||||
clearSsoContinuation();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/** 清理已完成或无效的登录续跳请求。 */
|
||||
export function clearSsoContinuation(): void {
|
||||
sessionStorage.removeItem(STORAGE_KEY);
|
||||
}
|
||||
|
||||
/** 生成只包含服务端应用 key 的 HXOPS 授权路由。 */
|
||||
export function continuationLocation(continuation: SsoContinuation) {
|
||||
return {
|
||||
path: '/sso/authorize',
|
||||
query: {
|
||||
app: continuation.app,
|
||||
state: continuation.state,
|
||||
},
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
/**
|
||||
* features/sso/utils/postForm.ts
|
||||
* 用途:用浏览器表单 POST 将短时 SSO assertion 交给已登记的平级服务回调。
|
||||
* 依赖:DOM API。
|
||||
* 逻辑:assertion 只进入请求体,不拼接 URL;提交后浏览器离开 HXOPS 授权页。
|
||||
*/
|
||||
|
||||
/**
|
||||
* POST assertion 和 state 到后端返回的已登记回调地址。
|
||||
* @param action - HXOPS 服务端从应用注册表返回的绝对 HTTPS callback URL。
|
||||
* @param fields - 仅包含 assertion 与平级服务原始 state。
|
||||
*/
|
||||
export function submitSsoForm(action: string, fields: Record<string, string>): void {
|
||||
const form = document.createElement('form');
|
||||
form.method = 'POST';
|
||||
form.action = action;
|
||||
form.style.display = 'none';
|
||||
for (const [name, value] of Object.entries(fields)) {
|
||||
const input = document.createElement('input');
|
||||
input.type = 'hidden';
|
||||
input.name = name;
|
||||
input.value = value;
|
||||
form.appendChild(input);
|
||||
}
|
||||
document.body.appendChild(form);
|
||||
form.submit();
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
<!--
|
||||
features/sso/views/SsoAuthorizeView.vue
|
||||
用途:承接平级服务登录请求;未登录时转 HXOPS 登录页,已登录时签发 assertion 并 POST 回平级服务。
|
||||
依赖:auth store、SSO API、continuation 与 postForm 工具。
|
||||
逻辑:平级服务只提供 app/state;callback 与 JWT audience 始终由 HXOPS 服务端注册表决定。
|
||||
-->
|
||||
<script setup lang="ts">
|
||||
import { onMounted, ref } from 'vue';
|
||||
import { ArrowLeft, Loader2 } from 'lucide-vue-next';
|
||||
import { useI18n } from 'vue-i18n';
|
||||
import { useRoute, useRouter } from 'vue-router';
|
||||
import { useAuthStore } from '@/features/auth/stores/auth.store';
|
||||
import { createSsoAssertion } from '../api/sso.api';
|
||||
import {
|
||||
clearSsoContinuation,
|
||||
parseSsoContinuation,
|
||||
saveSsoContinuation,
|
||||
} from '../utils/continuation';
|
||||
import { submitSsoForm } from '../utils/postForm';
|
||||
|
||||
const { t } = useI18n();
|
||||
const route = useRoute();
|
||||
const router = useRouter();
|
||||
const authStore = useAuthStore();
|
||||
const errorMessage = ref('');
|
||||
|
||||
/** 校验授权请求,并按当前登录状态执行保存续跳或签发短时 assertion。 */
|
||||
async function authorize(): Promise<void> {
|
||||
const continuation = parseSsoContinuation(route.query);
|
||||
if (!continuation) {
|
||||
errorMessage.value = t('common.sso.invalidRequest');
|
||||
return;
|
||||
}
|
||||
|
||||
authStore.syncFromStorage();
|
||||
if (!authStore.isLoggedIn) {
|
||||
saveSsoContinuation(continuation);
|
||||
await router.replace('/login');
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
const result = await createSsoAssertion(continuation.app, continuation.state);
|
||||
clearSsoContinuation();
|
||||
submitSsoForm(result.post_url, { assertion: result.assertion, state: result.state });
|
||||
} catch (error) {
|
||||
errorMessage.value = (error as Error)?.message || t('common.sso.failed');
|
||||
}
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
void authorize();
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<main class="page-shell flex min-h-screen items-center justify-center px-6">
|
||||
<section class="w-full max-w-md rounded-2xl border border-default bg-surface p-8 text-center shadow-xl">
|
||||
<template v-if="!errorMessage">
|
||||
<Loader2 class="mx-auto h-10 w-10 animate-spin text-brand-600" />
|
||||
<h1 class="mt-5 text-xl font-semibold text-primary">{{ t('common.sso.authorizing') }}</h1>
|
||||
<p class="mt-2 text-sm text-muted">{{ t('common.sso.authorizingHint') }}</p>
|
||||
</template>
|
||||
<template v-else>
|
||||
<h1 class="text-xl font-semibold text-primary">{{ t('common.sso.failed') }}</h1>
|
||||
<p class="mt-3 text-sm text-red-600">{{ errorMessage }}</p>
|
||||
<button type="button" class="btn-secondary mt-6 inline-flex items-center gap-2" @click="router.replace('/workspace/applications')">
|
||||
<ArrowLeft class="h-4 w-4" /> {{ t('common.sso.backToHxops') }}
|
||||
</button>
|
||||
</template>
|
||||
</section>
|
||||
</main>
|
||||
</template>
|
||||
@@ -0,0 +1,63 @@
|
||||
<!--
|
||||
features/sso/views/SsoLaunchView.vue
|
||||
用途:在新标签先继承 HXOPS sessionStorage,再安全跳转到平级服务登录起点。
|
||||
依赖:SSO 应用目录 API、Vue Router。
|
||||
逻辑:页面只接收 app key,加载后立即切断 opener,目标 URL 由 HXOPS 服务端注册表提供。
|
||||
-->
|
||||
<script setup lang="ts">
|
||||
import { onMounted, ref } from 'vue';
|
||||
import { ArrowLeft, Loader2 } from 'lucide-vue-next';
|
||||
import { useI18n } from 'vue-i18n';
|
||||
import { useRoute, useRouter } from 'vue-router';
|
||||
import { listSsoApplications } from '../api/sso.api';
|
||||
|
||||
const { t } = useI18n();
|
||||
const route = useRoute();
|
||||
const router = useRouter();
|
||||
const errorMessage = ref('');
|
||||
|
||||
// 新标签已完成同源 sessionStorage 克隆,跳跨域前切断 opener 防止反向标签劫持。
|
||||
window.opener = null;
|
||||
|
||||
/** 按服务端应用目录解析 app key,并跳转到平级服务登录起点。 */
|
||||
async function launch(): Promise<void> {
|
||||
const appKey = typeof route.query.app === 'string' ? route.query.app.trim().toLowerCase() : '';
|
||||
if (!appKey) {
|
||||
errorMessage.value = t('common.sso.invalidRequest');
|
||||
return;
|
||||
}
|
||||
try {
|
||||
const applications = await listSsoApplications();
|
||||
const application = applications.find((item) => item.key === appKey);
|
||||
if (!application) {
|
||||
errorMessage.value = t('errors.codes.AUTH_SSO_APP_NOT_FOUND');
|
||||
return;
|
||||
}
|
||||
window.location.replace(application.login_url);
|
||||
} catch (error) {
|
||||
errorMessage.value = (error as Error)?.message || t('common.sso.failed');
|
||||
}
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
void launch();
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<main class="page-shell flex min-h-screen items-center justify-center px-6">
|
||||
<section class="w-full max-w-md rounded-2xl border border-default bg-surface p-8 text-center shadow-xl">
|
||||
<template v-if="!errorMessage">
|
||||
<Loader2 class="mx-auto h-10 w-10 animate-spin text-brand-600" />
|
||||
<h1 class="mt-5 text-xl font-semibold text-primary">{{ t('common.sso.authorizing') }}</h1>
|
||||
</template>
|
||||
<template v-else>
|
||||
<h1 class="text-xl font-semibold text-primary">{{ t('common.sso.failed') }}</h1>
|
||||
<p class="mt-3 text-sm text-red-600">{{ errorMessage }}</p>
|
||||
<button type="button" class="btn-secondary mt-6 inline-flex items-center gap-2" @click="router.replace('/workspace/applications')">
|
||||
<ArrowLeft class="h-4 w-4" /> {{ t('common.sso.backToHxops') }}
|
||||
</button>
|
||||
</template>
|
||||
</section>
|
||||
</main>
|
||||
</template>
|
||||
@@ -1,7 +1,7 @@
|
||||
<script setup lang="ts">
|
||||
/**
|
||||
* features/workspace/components/WorkspaceSidebar.vue
|
||||
* 工作台左侧导航:子路由链接、返回聊天与退出登录。
|
||||
* 工作台左侧导航:子路由链接、第三方系统、返回聊天与退出登录。
|
||||
*/
|
||||
import { inject } from 'vue';
|
||||
import { useRoute } from 'vue-router';
|
||||
@@ -10,6 +10,7 @@ import {
|
||||
} from 'lucide-vue-next';
|
||||
import { WORKSPACE_PATHS } from '../constants/routes';
|
||||
import { WORKSPACE_KEY } from '../composables/workspace.context';
|
||||
import { ExternalSystemLinks } from '@/features/sso';
|
||||
|
||||
defineProps<{
|
||||
collapsed?: boolean;
|
||||
@@ -106,6 +107,7 @@ function isActive(match: readonly string[]) {
|
||||
|
||||
<div class="border-t border-subtle pt-4">
|
||||
<div class="space-y-2">
|
||||
<ExternalSystemLinks :compact="Boolean(collapsed)" :show-label="!collapsed" />
|
||||
<button
|
||||
type="button"
|
||||
@click="ws.navigateToGeneralChat"
|
||||
|
||||
@@ -10,6 +10,7 @@ import { useWorkspace } from '../composables/useWorkspace';
|
||||
import { WORKSPACE_KEY } from '../composables/workspace.context';
|
||||
import WorkspaceSidebar from '../components/WorkspaceSidebar.vue';
|
||||
import WorkspaceModals from '../components/WorkspaceModals.vue';
|
||||
import { ExternalSystemLinks } from '@/features/sso';
|
||||
|
||||
const ws = useWorkspace();
|
||||
provide(WORKSPACE_KEY, ws);
|
||||
@@ -40,6 +41,7 @@ const mobileTabs = [
|
||||
</button>
|
||||
<span class="text-sm font-semibold text-primary">{{ ws.mobileTabTitle }}</span>
|
||||
</div>
|
||||
<ExternalSystemLinks compact :show-label="false" />
|
||||
</header>
|
||||
|
||||
<div
|
||||
|
||||
@@ -8,6 +8,13 @@
|
||||
"refresh": "Refresh",
|
||||
"yes": "Yes",
|
||||
"no": "No",
|
||||
"sso": {
|
||||
"authorizing": "Opening the external system",
|
||||
"authorizingHint": "Completing secure single sign-on. Please wait.",
|
||||
"failed": "Single sign-on failed",
|
||||
"invalidRequest": "The external login request is invalid or expired. Start again from the target system.",
|
||||
"backToHxops": "Back to HXOPS"
|
||||
},
|
||||
"deleteDialog": {
|
||||
"defaultTitle": "Are you sure you want to delete?",
|
||||
"defaultMessage": "When clicked the OK button, this dialog will be closed after 1 second",
|
||||
|
||||
@@ -6,6 +6,11 @@
|
||||
"AUTH_INCORRECT_CURRENT_PASSWORD": "Incorrect current password",
|
||||
"AUTH_USER_NOT_FOUND": "User not found",
|
||||
"AUTH_ACCOUNT_DISABLED": "Account is disabled",
|
||||
"AUTH_CASDOOR_IDENTITY_INVALID": "Casdoor did not return a stable user identity. Check the OIDC configuration.",
|
||||
"AUTH_SSO_CONFIG_ERROR": "The SSO application configuration is invalid. Contact an administrator.",
|
||||
"AUTH_SSO_APP_NOT_FOUND": "The target system is not configured or is disabled.",
|
||||
"AUTH_SSO_IDENTITY_UNSUPPORTED": "The current session is not backed by Casdoor. Log in again and retry.",
|
||||
"AUTH_SSO_ASSERTION_ISSUE_FAILED": "The peer-service login assertion could not be issued. Please retry.",
|
||||
"AUTH_FORBIDDEN": "You do not have permission to perform this action.",
|
||||
"RESOURCE_NOT_FOUND": "The requested resource was not found.",
|
||||
"RESOURCE_CONFLICT": "Request conflict. Please refresh and try again.",
|
||||
|
||||
@@ -8,6 +8,13 @@
|
||||
"refresh": "รีเฟรช",
|
||||
"yes": "ใช่",
|
||||
"no": "ไม่",
|
||||
"sso": {
|
||||
"authorizing": "กำลังเปิดระบบภายนอก",
|
||||
"authorizingHint": "กำลังดำเนินการเข้าสู่ระบบแบบครั้งเดียวอย่างปลอดภัย โปรดรอสักครู่",
|
||||
"failed": "การเข้าสู่ระบบแบบครั้งเดียวล้มเหลว",
|
||||
"invalidRequest": "คำขอเข้าสู่ระบบภายนอกไม่ถูกต้องหรือหมดอายุ โปรดเริ่มใหม่จากระบบเป้าหมาย",
|
||||
"backToHxops": "กลับไป HXOPS"
|
||||
},
|
||||
"deleteDialog": {
|
||||
"defaultTitle": "คุณแน่ใจหรือไม่ว่าต้องการลบ?",
|
||||
"defaultMessage": "เมื่อกดปุ่มตกลง กล่องโต้ตอบนี้จะปิดหลังจาก 1 วินาที",
|
||||
|
||||
@@ -6,6 +6,11 @@
|
||||
"AUTH_INCORRECT_CURRENT_PASSWORD": "รหัสผ่านปัจจุบันไม่ถูกต้อง",
|
||||
"AUTH_USER_NOT_FOUND": "ไม่พบผู้ใช้",
|
||||
"AUTH_ACCOUNT_DISABLED": "บัญชีถูกปิดใช้งาน",
|
||||
"AUTH_CASDOOR_IDENTITY_INVALID": "Casdoor ไม่ได้ส่งคืนข้อมูลระบุตัวผู้ใช้ที่คงที่ โปรดตรวจสอบการตั้งค่า OIDC",
|
||||
"AUTH_SSO_CONFIG_ERROR": "การตั้งค่าแอป SSO ไม่ถูกต้อง โปรดติดต่อผู้ดูแลระบบ",
|
||||
"AUTH_SSO_APP_NOT_FOUND": "ยังไม่ได้ตั้งค่าระบบเป้าหมายหรือระบบถูกปิดใช้งาน",
|
||||
"AUTH_SSO_IDENTITY_UNSUPPORTED": "เซสชันปัจจุบันไม่ได้ยืนยันผ่าน Casdoor โปรดเข้าสู่ระบบใหม่",
|
||||
"AUTH_SSO_ASSERTION_ISSUE_FAILED": "ไม่สามารถออกข้อมูลยืนยันการเข้าสู่ระบบสำหรับบริการในผลิตภัณฑ์ได้ โปรดลองใหม่",
|
||||
"AUTH_FORBIDDEN": "คุณไม่มีสิทธิ์ดำเนินการนี้",
|
||||
"RESOURCE_NOT_FOUND": "ไม่พบทรัพยากรที่ร้องขอ",
|
||||
"RESOURCE_CONFLICT": "คำขอขัดแย้ง โปรดรีเฟรชแล้วลองใหม่",
|
||||
|
||||
@@ -8,6 +8,13 @@
|
||||
"refresh": "刷新",
|
||||
"yes": "是",
|
||||
"no": "否",
|
||||
"sso": {
|
||||
"authorizing": "正在进入第三方系统",
|
||||
"authorizingHint": "正在安全地完成统一登录,请稍候。",
|
||||
"failed": "统一登录失败",
|
||||
"invalidRequest": "第三方登录请求无效或已过期,请从目标系统重新发起。",
|
||||
"backToHxops": "返回 HXOPS"
|
||||
},
|
||||
"deleteDialog": {
|
||||
"defaultTitle": "您确定要删除吗?",
|
||||
"defaultMessage": "点击“确定”按钮后,该对话框将在 1 秒后关闭",
|
||||
|
||||
@@ -6,6 +6,11 @@
|
||||
"AUTH_INCORRECT_CURRENT_PASSWORD": "当前密码不正确",
|
||||
"AUTH_USER_NOT_FOUND": "用户不存在",
|
||||
"AUTH_ACCOUNT_DISABLED": "账号已禁用",
|
||||
"AUTH_CASDOOR_IDENTITY_INVALID": "Casdoor 未返回稳定用户身份,请联系管理员检查 OIDC 配置。",
|
||||
"AUTH_SSO_CONFIG_ERROR": "统一登录应用配置无效,请联系管理员。",
|
||||
"AUTH_SSO_APP_NOT_FOUND": "目标系统未配置或已停用。",
|
||||
"AUTH_SSO_IDENTITY_UNSUPPORTED": "当前登录不是 Casdoor 身份,请重新登录后重试。",
|
||||
"AUTH_SSO_ASSERTION_ISSUE_FAILED": "平级服务登录声明签发失败,请重试。",
|
||||
"AUTH_FORBIDDEN": "你没有权限执行该操作。",
|
||||
"RESOURCE_NOT_FOUND": "请求的资源不存在。",
|
||||
"RESOURCE_CONFLICT": "请求冲突,请刷新后重试。",
|
||||
|
||||
@@ -8,6 +8,13 @@
|
||||
"refresh": "刷新",
|
||||
"yes": "是",
|
||||
"no": "否",
|
||||
"sso": {
|
||||
"authorizing": "正在進入第三方系統",
|
||||
"authorizingHint": "正在安全地完成統一登入,請稍候。",
|
||||
"failed": "統一登入失敗",
|
||||
"invalidRequest": "第三方登入請求無效或已過期,請從目標系統重新發起。",
|
||||
"backToHxops": "返回 HXOPS"
|
||||
},
|
||||
"deleteDialog": {
|
||||
"defaultTitle": "您確定要刪除嗎?",
|
||||
"defaultMessage": "點擊「確定」按鈕後,此對話框將在 1 秒後關閉",
|
||||
|
||||
@@ -6,6 +6,11 @@
|
||||
"AUTH_INCORRECT_CURRENT_PASSWORD": "當前密碼不正確",
|
||||
"AUTH_USER_NOT_FOUND": "用戶不存在",
|
||||
"AUTH_ACCOUNT_DISABLED": "帳號已禁用",
|
||||
"AUTH_CASDOOR_IDENTITY_INVALID": "Casdoor 未返回穩定用戶身份,請聯絡管理員檢查 OIDC 設定。",
|
||||
"AUTH_SSO_CONFIG_ERROR": "統一登入應用設定無效,請聯絡管理員。",
|
||||
"AUTH_SSO_APP_NOT_FOUND": "目標系統未設定或已停用。",
|
||||
"AUTH_SSO_IDENTITY_UNSUPPORTED": "目前登入不是 Casdoor 身份,請重新登入後再試。",
|
||||
"AUTH_SSO_ASSERTION_ISSUE_FAILED": "平級服務登入聲明簽發失敗,請重試。",
|
||||
"AUTH_FORBIDDEN": "你沒有權限執行此操作。",
|
||||
"RESOURCE_NOT_FOUND": "請求的資源不存在。",
|
||||
"RESOURCE_CONFLICT": "請求衝突,請刷新後重試。",
|
||||
|
||||
@@ -26,6 +26,7 @@ window.fetch = async (input: RequestInfo | URL, init?: RequestInit): Promise<Res
|
||||
url.includes('/api/user/login') ||
|
||||
url.includes('/api/user/casdoor/password-login') ||
|
||||
url.includes('/api/user/casdoor/login');
|
||||
const isOptionalSsoCatalogApi = /\/api\/sso\/apps(?:\?|$)/.test(url);
|
||||
if (res.status === 401 && isApi && !isRefreshApi) {
|
||||
const refreshed = await refreshAccessToken();
|
||||
if (refreshed) {
|
||||
@@ -35,7 +36,7 @@ window.fetch = async (input: RequestInfo | URL, init?: RequestInit): Promise<Res
|
||||
res = await runFetch(reqInit);
|
||||
}
|
||||
}
|
||||
if (res.status === 401 && isApi && !isLoginApi) {
|
||||
if (res.status === 401 && isApi && !isLoginApi && !isOptionalSsoCatalogApi) {
|
||||
window.dispatchEvent(new CustomEvent('hxops:unauthorized', { detail: { url, status: res.status } }));
|
||||
}
|
||||
} catch {
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
* 全局路由 path 常量与公开路径判定。
|
||||
*/
|
||||
/** 无需登录即可访问的路由 path */
|
||||
export const PUBLIC_PATHS = ['/', '/login', '/casdoor-callback', '/reset-password'] as const;
|
||||
export const PUBLIC_PATHS = ['/', '/login', '/casdoor-callback', '/reset-password', '/sso/authorize'] as const;
|
||||
|
||||
/** 登录后首页默认跳转的 Agent ID */
|
||||
export const DEFAULT_CHAT_AGENT_ID = 16;
|
||||
|
||||
@@ -1,15 +1,17 @@
|
||||
<script setup lang="ts">
|
||||
/**
|
||||
* shared/layouts/AppHeaderTools.vue
|
||||
* 顶栏工具区:主题与语言切换。
|
||||
* 顶栏工具区:第三方系统、主题与语言切换。
|
||||
*/
|
||||
|
||||
import ThemeToggleButton from '@/shared/components/ThemeToggleButton.vue';
|
||||
import LocaleToggleButton from '@/shared/components/LocaleToggleButton.vue';
|
||||
import { ExternalSystemLinks } from '@/features/sso';
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="flex items-center gap-2">
|
||||
<ExternalSystemLinks />
|
||||
<ThemeToggleButton />
|
||||
<LocaleToggleButton />
|
||||
</div>
|
||||
|
||||
@@ -148,6 +148,7 @@ const clearAuthStorage = (): void => {
|
||||
sessionStorage.removeItem(AUTH_USER_KEY);
|
||||
sessionStorage.removeItem('hxops_wecom_state');
|
||||
sessionStorage.removeItem('hxops_casdoor_state');
|
||||
sessionStorage.removeItem('hxops_sso_continuation');
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
Reference in new issue
Block a user