fix: 完善单点登录传递回调地址和serverUrl的功能。优化token刷新机制,判断单点登录和管理员登录等等不同路径的处理机制。提示词管理的模板数据查找的时候只需要返回固定的5个类型。隐藏评查点设置中关于抽取的自定义模板的选择。

This commit is contained in:
2025-11-11 14:25:44 +08:00
parent 95381ddcc2
commit 12ec2ad7bd
11 changed files with 238 additions and 85 deletions
+24 -15
View File
@@ -1,10 +1,12 @@
/**
* 🔒 服务器端专用:OAuth 敏感配置
*
*
* 此文件只在服务器端运行,确保环境变量在运行时读取
* Remix 会自动排除 .server.ts 文件不打包到客户端
*/
import { OAUTH_CONFIG } from './api-config';
// 用于控制日志输出(避免重复日志)
let hasLoggedSecret = false;
@@ -14,17 +16,17 @@ let hasLoggedSecret = false;
*/
export function getOAuthClientSecret(): string {
const secret = process.env.OAUTH_CLIENT_SECRET;
// 只在第一次调用时输出详细日志(避免启动时就输出)
if (!hasLoggedSecret) {
hasLoggedSecret = true;
console.log('🔍 [oauth-secret.server] 读取 OAUTH_CLIENT_SECRET:');
console.log(' - 值存在:', !!secret);
console.log(' - 值长度:', secret?.length || 0);
console.log(' - 值预览:', secret ? `${secret.substring(0, 10)}...` : 'undefined');
console.log(' - 是否为占位符:', secret === 'placeholder' || secret === 'none');
if (!secret || secret === 'placeholder' || secret === 'none') {
console.warn('⚠️ 警告:未设置有效的 OAUTH_CLIENT_SECRET 环境变量');
console.warn('⚠️ 当前值:', secret);
@@ -34,26 +36,33 @@ export function getOAuthClientSecret(): string {
console.log('✅ [oauth-secret.server] OAUTH_CLIENT_SECRET 已成功读取');
}
}
return secret || '';
}
/**
* 获取服务器端 OAuth 配置
* 使用 api-config.ts 中根据端口号配置的 OAuth 配置
* 只有 clientSecret 从环境变量获取
*/
export function getServerOAuthConfigRuntime() {
const secret = getOAuthClientSecret();
// 从基础配置中获取其他 OAuth 参数
const baseConfig = {
serverUrl: process.env.NEXT_PUBLIC_OAUTH_SERVER_URL || 'http://10.79.112.85',
clientId: process.env.NEXT_PUBLIC_OAUTH_CLIENT_ID || '54d2a619fe5c81ae1250434c441fccccqMtKwh7H4fO',
redirectUri: process.env.NEXT_PUBLIC_OAUTH_REDIRECT_URI || 'http://10.79.97.17/',
appId: process.env.NEXT_PUBLIC_OAUTH_APP_ID || 'idaasoauth2',
};
// 使用 api-config.ts 中根据端口号配置的 OAuth 配置
// 只覆盖 clientSecret 为从环境变量读取的值
console.log('🔧 [oauth-secret.server] 使用端口配置的 OAuth 配置:', {
serverUrl: OAUTH_CONFIG.serverUrl,
clientId: OAUTH_CONFIG.clientId,
redirectUri: OAUTH_CONFIG.redirectUri,
appId: OAUTH_CONFIG.appId,
hasClientSecret: !!secret
});
return {
...baseConfig,
serverUrl: OAUTH_CONFIG.serverUrl!,
clientId: OAUTH_CONFIG.clientId!,
redirectUri: OAUTH_CONFIG.redirectUri!,
appId: OAUTH_CONFIG.appId!,
clientSecret: secret
};
}