mirror of
https://gitee.com/dotnetchina/OpenAuth.Net.git
synced 2026-07-14 11:33:47 +08:00
🐛fix: #IJX34Q 非Identity的token支持jwt token
This commit is contained in:
@@ -13,6 +13,7 @@ using SqlSugar;
|
||||
using Infrastructure.Extensions.AutofacManager;
|
||||
using Infrastructure.Utilities;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.Extensions.Options;
|
||||
|
||||
|
||||
namespace OpenAuth.App.SSO
|
||||
@@ -24,11 +25,13 @@ namespace OpenAuth.App.SSO
|
||||
protected ISqlSugarClient SugarClient;
|
||||
private ICacheContext _cacheContext;
|
||||
private AppManager _appInfoService;
|
||||
private IOptions<AppSetting> _appConfiguration;
|
||||
|
||||
public LoginParse( AppManager infoService, ICacheContext cacheContext, ISqlSugarClient client)
|
||||
public LoginParse( AppManager infoService, ICacheContext cacheContext, ISqlSugarClient client, IOptions<AppSetting> appConfiguration)
|
||||
{
|
||||
_appInfoService = infoService;
|
||||
_cacheContext = cacheContext;
|
||||
_appConfiguration = appConfiguration;
|
||||
string tenantId = Define.DEFAULT_TENANT_ID;
|
||||
var httpContextAccessor = AutofacContainerModule.GetService<IHttpContextAccessor>();
|
||||
if (httpContextAccessor != null)
|
||||
@@ -87,21 +90,33 @@ namespace OpenAuth.App.SSO
|
||||
throw new Exception("账号状态异常,可能已停用");
|
||||
}
|
||||
|
||||
// 生成唯一的会话ID作为缓存Key
|
||||
var sessionId = Guid.NewGuid().ToString("N");
|
||||
var expireDays = _appConfiguration.Value.JwtExpireDays;
|
||||
|
||||
var currentSession = new UserAuthSession
|
||||
{
|
||||
Account = model.Account,
|
||||
Name = sysUserInfo.Name,
|
||||
Token = Guid.NewGuid().ToString().GetHashCode().ToString("x"),
|
||||
Token = sessionId,
|
||||
AppKey = model.AppKey,
|
||||
CreateTime = TimeHelper.Now
|
||||
// , IpAddress = HttpContext.Current.Request.UserHostAddress
|
||||
};
|
||||
|
||||
//创建Session
|
||||
_cacheContext.Set(currentSession.Token, currentSession, TimeHelper.Now.AddDays(10));
|
||||
//创建Session缓存,用于登出时失效判定
|
||||
_cacheContext.Set(sessionId, currentSession, TimeHelper.Now.AddDays(expireDays));
|
||||
|
||||
// 生成JWT Token
|
||||
var jwtToken = JwtTokenHelper.GenerateToken(
|
||||
model.Account,
|
||||
sysUserInfo.Name,
|
||||
model.AppKey,
|
||||
sessionId,
|
||||
_appConfiguration.Value.JwtSecret,
|
||||
expireDays);
|
||||
|
||||
result.Code = 200;
|
||||
result.Token = currentSession.Token;
|
||||
result.Token = jwtToken;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user