将通用SSO配置从JSON文件迁移至appsettings配置 移除旧的JSON配置文件并更新.gitignore 添加对IConfiguration的支持并保持向后兼容
64 lines
1.7 KiB
C#
64 lines
1.7 KiB
C#
using Microsoft.Extensions.Configuration;
|
|
|
|
namespace YLErp.Web.Models
|
|
{
|
|
/// <summary>
|
|
/// 通用单点登录配置
|
|
/// </summary>
|
|
public static class GeneralSSOConfig
|
|
{
|
|
static InnerConfig _config;
|
|
|
|
/// <summary>
|
|
/// 通用SSO登录是否启用
|
|
/// </summary>
|
|
public static bool Enable => _config != null && _config.enable;
|
|
|
|
/// <summary>
|
|
/// 通用SSO授权地址(SSO服务器的登录地址)
|
|
/// </summary>
|
|
public static string AuthUrl => _config?.auth_url;
|
|
|
|
/// <summary>
|
|
/// 通用SSO回调地址(本系统的回调处理地址)
|
|
/// </summary>
|
|
public static string CallbackUrl => _config?.callback_url;
|
|
|
|
/// <summary>
|
|
/// 通用SSO获取用户信息接口地址
|
|
/// </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()
|
|
{
|
|
// 保留旧方法以保持向后兼容
|
|
}
|
|
|
|
class InnerConfig
|
|
{
|
|
public bool enable { get; set; }
|
|
|
|
public string auth_url { get; set; }
|
|
|
|
public string callback_url { get; set; }
|
|
|
|
public string get_user_url { get; set; }
|
|
}
|
|
}
|
|
}
|