fix RedisHelper wxTokenKeyPrefix
This commit is contained in:
@ -1,5 +1,6 @@
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using QYZH.InteractiveMagazine.Infrastructure.Auth;
|
||||
using QYZH.InteractiveMagazine.Models.Settings;
|
||||
using System.IdentityModel.Tokens.Jwt;
|
||||
|
||||
@ -60,7 +61,11 @@ public class JwtAutoRefreshMiddleware
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var wxUserId = jwtToken.Claims.FirstOrDefault(c => c.Type == JwtHelper.WxUserIdClaimType)?.Value;
|
||||
if (string.IsNullOrEmpty(wxUserId))
|
||||
{
|
||||
return;
|
||||
}
|
||||
var jwtSettings = _configuration.GetSection("JwtSettings").Get<JwtSettings>();
|
||||
if (jwtSettings == null || jwtSettings.ExpiryMinutes <= 0)
|
||||
{
|
||||
@ -68,7 +73,7 @@ public class JwtAutoRefreshMiddleware
|
||||
}
|
||||
|
||||
// 每次请求都刷新 Redis 中 Token 的过期时间
|
||||
await RefreshRedisTokenExpiryAsync(userId, token, jwtSettings.ExpiryMinutes);
|
||||
await RefreshRedisTokenExpiryAsync(wxUserId,userId, token, jwtSettings.ExpiryMinutes);
|
||||
}
|
||||
catch
|
||||
{
|
||||
@ -79,7 +84,7 @@ public class JwtAutoRefreshMiddleware
|
||||
/// <summary>
|
||||
/// 刷新 Redis 中已存在 Token 的过期时间(保持会话活跃)
|
||||
/// </summary>
|
||||
private async Task RefreshRedisTokenExpiryAsync(string userId, string currentToken, int expiryMinutes)
|
||||
private async Task RefreshRedisTokenExpiryAsync(string wxUserId,string userId, string currentToken, int expiryMinutes)
|
||||
{
|
||||
// 检查 Admin Token
|
||||
var adminTokenKey = $"{AdminTokenKeyPrefix}:{userId}";
|
||||
@ -91,7 +96,7 @@ public class JwtAutoRefreshMiddleware
|
||||
}
|
||||
|
||||
// 检查 WeChat Token
|
||||
var wechatTokenKey = $"{WeChatTokenKeyPrefix}:{userId}";
|
||||
var wechatTokenKey = $"{WeChatTokenKeyPrefix}:{wxUserId}{userId}";
|
||||
var wechatToken = await RedisHelper.GetAsync(wechatTokenKey);
|
||||
if (!string.IsNullOrEmpty(wechatToken))
|
||||
{
|
||||
|
||||
@ -327,7 +327,7 @@ public class WeChatAuthService(
|
||||
var jwtSettings = GetJwtSettings();
|
||||
var token = JwtHelper.GenerateToken(wxUser.Id, userId, userName, jwtSettings);
|
||||
|
||||
await RedisHelper.SetAsync($"{TokenKeyPrefix}:{userId}", token, TimeSpan.FromMinutes(jwtSettings.ExpiryMinutes));
|
||||
await RedisHelper.SetAsync($"{TokenKeyPrefix}:{wxUser.Id}{userId}", token, TimeSpan.FromMinutes(jwtSettings.ExpiryMinutes));
|
||||
|
||||
return new WeChatLoginOutput
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user