From dcd1e3feaff24be2377b1a83d221f1ce643bbfa6 Mon Sep 17 00:00:00 2001 From: berlin-tzen Date: Sat, 7 Jan 2023 17:15:39 +0800 Subject: [PATCH] =?UTF-8?q?[WHAT]=20=E4=BB=A5authtoken=E5=8F=96=E4=BB=A3Me?= =?UTF-8?q?mberID=EF=BC=8C=E4=B8=A6=E5=A2=9E=E5=8A=A0Token=E8=A7=A3?= =?UTF-8?q?=E6=9E=90=E5=B7=A5=E5=85=B7=20[WHY]=20ShowEasy=20=E5=BE=8C?= =?UTF-8?q?=E5=8F=B0=E9=96=8B=E7=99=BC=20[HOW]=20API=20=E9=96=8B=E7=99=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- EuroTran/EasyBL.WEBAPP/EasyBL.WEBAPP.csproj | 1 + EuroTran/EasyBL.WEBAPP/SETokenUtil.cs | 54 +++++++++++++++++++ EuroTran/Entity/Entity.csproj | 1 + EuroTran/Entity/SEToken.cs | 32 +++++++++++ .../WebApp/Controllers/FavoriteController.cs | 23 ++++++-- 5 files changed, 107 insertions(+), 4 deletions(-) create mode 100644 EuroTran/EasyBL.WEBAPP/SETokenUtil.cs create mode 100644 EuroTran/Entity/SEToken.cs diff --git a/EuroTran/EasyBL.WEBAPP/EasyBL.WEBAPP.csproj b/EuroTran/EasyBL.WEBAPP/EasyBL.WEBAPP.csproj index e4725e5..a68ce57 100644 --- a/EuroTran/EasyBL.WEBAPP/EasyBL.WEBAPP.csproj +++ b/EuroTran/EasyBL.WEBAPP/EasyBL.WEBAPP.csproj @@ -81,6 +81,7 @@ + diff --git a/EuroTran/EasyBL.WEBAPP/SETokenUtil.cs b/EuroTran/EasyBL.WEBAPP/SETokenUtil.cs new file mode 100644 index 0000000..e5de755 --- /dev/null +++ b/EuroTran/EasyBL.WEBAPP/SETokenUtil.cs @@ -0,0 +1,54 @@ +using Entity; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Net.Http; +using System.Text; +using System.Threading.Tasks; + +namespace EasyBL.WEBAPP +{ + public static class SETokenUtil + { + + public static SEToken GetToken(HttpRequestMessage message) { + + SEToken seToken = new SEToken(); + + IEnumerable headerValues; + if (message.Headers.TryGetValues("authtoken", out headerValues)) + { + var token = headerValues.FirstOrDefault(); + + seToken = Decrypt(token); + + } + + return seToken; + + } + + public static SEToken Decrypt(string data) { + + SEToken seToken = new SEToken(); + + if (!string.IsNullOrEmpty(data)) { + + var authtoken = EasyNet.SecurityUtil.Decrypt(data); + var saAuthtoken = authtoken.Split(','); + + seToken.OrgID = saAuthtoken[0].Split(':')[1]; + seToken.Email = saAuthtoken[1].Split(':')[1]; + seToken.MemberID = saAuthtoken[1].Split(':')[1]; + seToken.SignToken = saAuthtoken[2].Split(':')[1]; + + } + + return seToken; + } + + + + + } +} diff --git a/EuroTran/Entity/Entity.csproj b/EuroTran/Entity/Entity.csproj index 7b4afeb..74dd0d0 100644 --- a/EuroTran/Entity/Entity.csproj +++ b/EuroTran/Entity/Entity.csproj @@ -187,6 +187,7 @@ True True + diff --git a/EuroTran/Entity/SEToken.cs b/EuroTran/Entity/SEToken.cs new file mode 100644 index 0000000..f01a8a5 --- /dev/null +++ b/EuroTran/Entity/SEToken.cs @@ -0,0 +1,32 @@ +using System; + +namespace Entity +{ + public class SEToken + { + /// + /// 組織ID + /// + public string OrgID { get; set; } + + /// + /// 用户ID + /// + public string MemberID { get; set; } + + /// + /// 用户Email + /// + public string Email { get; set; } + + /// + /// 用户名对应签名Token + /// + public string SignToken { get; set; } + + /// + /// Token过期时间 + /// + public DateTime ExpireTime { get; set; } + } +} \ No newline at end of file diff --git a/EuroTran/WebApp/Controllers/FavoriteController.cs b/EuroTran/WebApp/Controllers/FavoriteController.cs index e03df2d..2339b42 100644 --- a/EuroTran/WebApp/Controllers/FavoriteController.cs +++ b/EuroTran/WebApp/Controllers/FavoriteController.cs @@ -2,7 +2,9 @@ using EasyBL.WebApi.Common; using EasyBL.WebApi.Filters; using EasyBL.WebApi.Message; +using EasyBL.WEBAPP; using EasyBL.WEBAPP.SYS; +using EasyNet; using Entity.ShowEasyDtos; using Entity.Sugar; using Newtonsoft.Json; @@ -22,27 +24,40 @@ namespace WebApp.Controllers [SEApiSecurityFilter] public HttpResponseMessage Favorite([FromBody] FavoriteDTO favorite) { + + // get authtoken + var SEToken = SETokenUtil.GetToken(this.Request); + favorite.MemberID = SEToken.Email; + return new FavoriteService().SaveFavorite(favorite); } [HttpGet] [SEApiSecurityFilter] - public HttpResponseMessage Favorites(string MemberID) + public HttpResponseMessage Favorites() { + // get authtoken + var SEToken = SETokenUtil.GetToken(this.Request); + + // get MemberID from authtoken + FavoriteDTO favorite = new FavoriteDTO(); - favorite.MemberID = MemberID; + favorite.MemberID = SEToken.Email; return new FavoriteService().GetFavorites(favorite); } [HttpGet] [SEApiSecurityFilter] - public HttpResponseMessage Favorites(string MemberID, string Type) + public HttpResponseMessage Favorites(string Type) { + // get authtoken + var SEToken = SETokenUtil.GetToken(this.Request); + FavoriteDTO favorite = new FavoriteDTO(); - favorite.MemberID = MemberID; + favorite.MemberID = SEToken.Email; favorite.Type = Type; return new FavoriteService().GetFavorites(favorite);