实现通用SSO单点登录功能,包括: 1. 新增SSO配置文件和模型类 2. 在登录页面添加SSO登录按钮 3. 实现SSO回调处理逻辑 4. 初始化SSO配置
52 lines
1.5 KiB
C#
52 lines
1.5 KiB
C#
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;
|
|
|
|
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
|
|
{
|
|
public bool enable { get; set; }
|
|
|
|
public string auth_url { get; set; }
|
|
|
|
public string callback_url { get; set; }
|
|
|
|
public string get_user_url { get; set; }
|
|
}
|
|
}
|
|
}
|