This commit is contained in:
陈淳
2022-09-15 18:40:24 +08:00
parent 489a0b6fb8
commit 844a7b455c
4 changed files with 35 additions and 9 deletions

View File

@@ -5,9 +5,11 @@ using Microsoft.IdentityModel.Tokens;
using System;
using System.IO;
using System.Text;
using System.Threading.Tasks;
using Yi.Framework.Common.Const;
using Yi.Framework.Common.Helper;
using Yi.Framework.Common.IOCOptions;
using Yi.Framework.Common.Models;
using Yi.Framework.Core;
namespace Yi.Framework.WebCore.MiddlewareExtend
@@ -25,15 +27,32 @@ namespace Yi.Framework.WebCore.MiddlewareExtend
services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
.AddJwtBearer(options =>
{
options.Events = new JwtBearerEvents
{
OnAuthenticationFailed = (context) =>
{
return Task.CompletedTask;
},
OnMessageReceived = (context) =>
{
return Task.CompletedTask;
},
OnChallenge = (context) =>
{
return Task.CompletedTask;
},
};
options.TokenValidationParameters = new TokenValidationParameters
{
ValidateIssuer = true,//是否验证Issuer
ValidateAudience = true,//是否验证Audience
ValidateLifetime = true,//是否验证失效时间
ValidateIssuerSigningKey = true,//是否验证SecurityKey
ValidAudience = jwtOptions.Audience,//Audience
ValidIssuer = jwtOptions.Issuer,//Issuer这两项和前面签发jwt的设置一致
IssuerSigningKey = new RsaSecurityKey(RSAFileHelper.GetPublicKey())
ClockSkew = TimeSpan.Zero,//过期缓冲时间
ValidateIssuer = true,//是否验证Issuer
ValidateAudience = true,//是否验证Audience
ValidateLifetime = true,//是否验证失效时间
ValidateIssuerSigningKey = true,//是否验证SecurityKey
ValidAudience = jwtOptions.Audience,//Audience
ValidIssuer = jwtOptions.Issuer,//Issuer这两项和前面签发jwt的设置一致
IssuerSigningKey = new RsaSecurityKey(RSAFileHelper.GetPublicKey())
};
});
return services;