feat: 后端完成双token刷新功能

This commit is contained in:
陈淳
2024-01-24 11:26:44 +08:00
parent c18334002c
commit c9e01e0782
7 changed files with 51 additions and 12 deletions

View File

@@ -25,6 +25,7 @@ using Yi.Framework.AspNetCore.Microsoft.AspNetCore.Builder;
using Yi.Framework.AspNetCore.Microsoft.Extensions.DependencyInjection;
using Yi.Framework.Bbs.Application;
using Yi.Framework.Rbac.Application;
using Yi.Framework.Rbac.Domain.Shared.Consts;
using Yi.Framework.Rbac.Domain.Shared.Options;
namespace Yi.Abp.Web
@@ -144,7 +145,7 @@ namespace Yi.Abp.Web
}
};
})
.AddJwtBearer("Refresh", options => {
.AddJwtBearer(TokenTypeConst.Refresh, options => {
options.TokenValidationParameters = new TokenValidationParameters
{
ClockSkew = TimeSpan.Zero,
@@ -153,6 +154,18 @@ namespace Yi.Abp.Web
ValidAudience = refreshJwtOptions.Audience,
IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(refreshJwtOptions.SecurityKey))
};
options.Events = new JwtBearerEvents
{
OnMessageReceived = context =>
{
var accessToken = context.Request.Query["refresh_token"];
if (!string.IsNullOrEmpty(accessToken))
{
context.Token = accessToken;
}
return Task.CompletedTask;
}
};
})
.AddQQ(options =>