refactor(SSO): 重构通用SSO配置初始化逻辑

将通用SSO配置从JSON文件迁移至appsettings配置
移除旧的JSON配置文件并更新.gitignore
添加对IConfiguration的支持并保持向后兼容
This commit is contained in:
shangzhongyuan
2026-03-05 10:19:40 +08:00
parent 759dbef2a9
commit a9a84ef5a1
5 changed files with 27 additions and 14 deletions
+2 -1
View File
@@ -1,4 +1,4 @@
## Ignore Visual Studio temporary files, build results, and
## Ignore Visual Studio temporary files, build results, and
## files generated by popular Visual Studio add-ons.
# User-specific files
@@ -223,5 +223,6 @@ logfile
/YLWebAPI/appsettings.Development.json
/YLManageAPI/appsettings.Development.json
/YLWebAPI/App_Docs
/.idea
/.idea/.idea.YLerpbase/.idea
/NuGet.Config
+1 -1
View File
@@ -70,7 +70,7 @@ namespace YLErp.Web
}
SsoLoginConfig.Init();
GeneralSSOConfig.Init();
GeneralSSOConfig.Init(config);
SetDefaultInitial();
}
-6
View File
@@ -1,6 +0,0 @@
{
"enable": true, //是否启用通用SSO登录
"auth_url": "http://127.0.0.1:8888/sso/login", //SSO授权地址
"callback_url": "http://localhost:49462/Account/Callback", //回调处理地址
"get_user_url": "http://127.0.0.1:8888/sso/getSsoUser" //获取用户信息接口地址
}
+18 -6
View File
@@ -1,3 +1,5 @@
using Microsoft.Extensions.Configuration;
namespace YLErp.Web.Models
{
/// <summary>
@@ -27,14 +29,24 @@ namespace YLErp.Web.Models
/// </summary>
public static string GetUserUrl => _config?.get_user_url;
/// <summary>
/// 初始化SSO配置
/// </summary>
/// <param name="config">配置对象</param>
public static void Init(IConfiguration config)
{
if (config != null)
{
_config = config.GetSection("GeneralSSO").Get<InnerConfig>();
}
}
/// <summary>
/// 初始化SSO配置(兼容旧方法)
/// </summary>
public static void Init()
{
var configFilePath = Server.MapPath("~/app_data/config/通用SSO.json");
if (System.IO.File.Exists(configFilePath))
{
var json = System.IO.File.ReadAllText(configFilePath);
_config = Newtonsoft.Json.JsonConvert.DeserializeObject<InnerConfig>(json);
}
// 保留旧方法以保持向后兼容
}
class InnerConfig
+6
View File
@@ -81,5 +81,11 @@
"ObjectClass": "ZSZQ_CWYSPJYQRSDZWF", //OA文件类别
"Urgent": 1, //紧急程度,1一般 2紧急 3加急
"Issend": 0 //流程是否自动发送,0不发送,1自动发送下一步
},
"GeneralSSO": {
"enable": true, //是否启用通用SSO登录
"auth_url": "http://127.0.0.1:8888/sso/login", //SSO授权地址
"callback_url": "http://localhost:49462/Account/Callback", //回调处理地址
"get_user_url": "http://127.0.0.1:8888/sso/getSsoUser" //获取用户信息接口地址
}
}