From a878d838d1f34db2c63cc48c44b1d88ebff376eb Mon Sep 17 00:00:00 2001 From: jackchenyang <874821510@qq.com> Date: Wed, 12 Jun 2024 13:57:52 +0800 Subject: [PATCH] 1221 --- FCL/FineUIPro.Web/FineUIPro.Web.csproj | 4 +-- FCL/FineUIPro.Web/packages.config | 2 +- FCL/FineUIPro.Web/ssocallback.aspx.cs | 36 ++++++++++++++++---------- 3 files changed, 25 insertions(+), 17 deletions(-) diff --git a/FCL/FineUIPro.Web/FineUIPro.Web.csproj b/FCL/FineUIPro.Web/FineUIPro.Web.csproj index ebfc00e..c0d8a24 100644 --- a/FCL/FineUIPro.Web/FineUIPro.Web.csproj +++ b/FCL/FineUIPro.Web/FineUIPro.Web.csproj @@ -138,8 +138,8 @@ ..\packages\System.Numerics.Vectors.4.5.0\lib\net46\System.Numerics.Vectors.dll - - ..\packages\System.Runtime.CompilerServices.Unsafe.4.7.1\lib\net461\System.Runtime.CompilerServices.Unsafe.dll + + ..\packages\System.Runtime.CompilerServices.Unsafe.6.0.0\lib\net461\System.Runtime.CompilerServices.Unsafe.dll diff --git a/FCL/FineUIPro.Web/packages.config b/FCL/FineUIPro.Web/packages.config index bc90019..994ad53 100644 --- a/FCL/FineUIPro.Web/packages.config +++ b/FCL/FineUIPro.Web/packages.config @@ -15,7 +15,7 @@ - + diff --git a/FCL/FineUIPro.Web/ssocallback.aspx.cs b/FCL/FineUIPro.Web/ssocallback.aspx.cs index a7c3270..36c73e6 100644 --- a/FCL/FineUIPro.Web/ssocallback.aspx.cs +++ b/FCL/FineUIPro.Web/ssocallback.aspx.cs @@ -1,11 +1,17 @@ using BLL; using BLL.Common; +using Microsoft.IdentityModel.Logging; +using Microsoft.IdentityModel.Tokens; using Newtonsoft.Json; +using Newtonsoft.Json.Linq; +using Org.BouncyCastle.Utilities.Encoders; using System; using System.Collections.Generic; using System.IdentityModel.Tokens.Jwt; using System.Linq; +using System.Text; using System.Web; +using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; @@ -16,6 +22,7 @@ namespace FineUIPro.Web private string code = string.Empty; protected void Page_Load(object sender, EventArgs e) { + this.code = Request.Params["code"]; BLL.ErrLogInfo.WriteLog($"获取code={this.code}"); if (string.IsNullOrEmpty(this.code)) @@ -23,7 +30,7 @@ namespace FineUIPro.Web Response.Redirect("~/login.aspx"); return; } - var token = GetAccessToken(this.code); + var token = GetAccessToken(this.code); var userInfo = getUserInfo(token); if (userInfo == null) { @@ -65,29 +72,30 @@ namespace FineUIPro.Web private Model.Sys_User getUserInfo(AccessTokenModel token) { - try { - var handler = new JwtSecurityTokenHandler(); - var jwtToken = handler.ReadJwtToken(token.id_token); string username = string.Empty; - var result = jwtToken.Claims.Where(t => t.Type == "cn").FirstOrDefault(); - if (result != null) + string[] toke_split= token.id_token.Split('.'); + var header = Encoding.UTF8.GetString(Base64UrlEncoder.DecodeBytes(toke_split[0])); + var clamis= Encoding.UTF8.GetString(Base64UrlEncoder.DecodeBytes(toke_split[1])); + BLL.ErrLogInfo.WriteLog("clamis=" + clamis); + JObject jo = JObject.Parse(clamis); + if (jo["cn"] != null) { - BLL.ErrLogInfo.WriteLog("cn="+result?.Value); - username = result?.Value; + username = jo["cn"].ToString(); } - else{ - username = jwtToken.Claims.Where(t => t.Type == "preferred_username").FirstOrDefault()?.Value; - BLL.ErrLogInfo.WriteLog("username=" + username); - if (!string.IsNullOrEmpty(username)) + else + { + if (jo["preferred_username"] != null) { - username = username.Split('@')[0]; - } + string preferred_username = jo["preferred_username"].ToString(); + username = preferred_username.Split('@')[0]; + } } var info = Funs.DB.Sys_User.Where(t => t.Account == username && t.IsPost == true).FirstOrDefault(); if (info != null) { + FormsAuthentication.SetAuthCookie(username, false); Session[SessionName.CurrUser] = info; }