From 5a94542cb6054587c67196ad1434e8db467703b5 Mon Sep 17 00:00:00 2001 From: douhandong Date: Tue, 28 May 2024 17:15:44 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B0=83=E6=95=B4=E8=8E=B7=E5=8F=96=E6=8E=88?= =?UTF-8?q?=E6=9D=83key,=E5=A2=9E=E5=8A=A0=E6=9D=83=E9=99=90=E7=9B=B8?= =?UTF-8?q?=E5=85=B3=E5=86=85=E5=AE=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Myshipping.Core/Service/Auth/AuthService.cs | 17 ++++++++++++----- Myshipping.Core/Service/Auth/Dto/LoginInput.cs | 7 +++++++ 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/Myshipping.Core/Service/Auth/AuthService.cs b/Myshipping.Core/Service/Auth/AuthService.cs index ea119fad..350826b6 100644 --- a/Myshipping.Core/Service/Auth/AuthService.cs +++ b/Myshipping.Core/Service/Auth/AuthService.cs @@ -19,6 +19,7 @@ using Furion.RemoteRequest.Extensions; using Newtonsoft.Json.Linq; using Microsoft.Extensions.Logging; using Myshipping.Core.Const; +using Newtonsoft.Json; namespace Myshipping.Core.Service; @@ -488,7 +489,7 @@ public class AuthService : IAuthService, IDynamicApiController, ITransient } //将key写入到redis 并指定五秒过期 string key = Guid.NewGuid().ToString(); - await _cache.SetTimeoutAsync( key, input.UserId, TimeSpan.FromSeconds(5)); + await _cache.SetTimeoutAsync( key, JsonConvert.SerializeObject( input), TimeSpan.FromSeconds(5)); //将key返回 return key; } @@ -508,11 +509,17 @@ public class AuthService : IAuthService, IDynamicApiController, ITransient { throw Oops.Bah("授权码无效"); } - //获取用户信息 - var user = _sysUserRep.AsQueryable().Filter(null, true).First(u => u.DjyUserId == _cache.Get(input.Key)); + //获取缓存数据 + GetAuthorizationKeyInput data = JsonConvert.DeserializeObject(_cache.Get(input.Key)); + + var datainfo = _sysUserRep.AsQueryable().Filter(null, true).First(u => u.DjyUserId == data.UserId); + + //获取缓存的权限,将权限缓存 + await _cache.SetAsync(datainfo.UserCode, data.Authority); + //获取对应租户 - var tenant = _sysTenantRep.Single(user.TenantId); + var tenant = _sysTenantRep.Single(datainfo.TenantId); //颁发token - return await GetLoginToken(user, tenant); + return await GetLoginToken(datainfo, tenant); } } diff --git a/Myshipping.Core/Service/Auth/Dto/LoginInput.cs b/Myshipping.Core/Service/Auth/Dto/LoginInput.cs index fdb06232..0093e9f3 100644 --- a/Myshipping.Core/Service/Auth/Dto/LoginInput.cs +++ b/Myshipping.Core/Service/Auth/Dto/LoginInput.cs @@ -1,5 +1,6 @@ using Furion.DependencyInjection; using System.ComponentModel.DataAnnotations; +using Ubiety.Dns.Core; namespace Myshipping.Core.Service; @@ -35,6 +36,12 @@ public class GetAuthorizationKeyInput /// 用户Id /// public string UserId { get; set; } + + /// + /// 权限范围 + /// + public string Authority { get; set; } + } ///