升级到.net5;增加文章栏目、商品分类快速修改排序;增加jwt授权登录
This commit is contained in:
+29
-1
@@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Text.Encodings.Web;
|
||||
using System.Text.Unicode;
|
||||
using System.Threading.Tasks;
|
||||
@@ -10,6 +11,7 @@ using COMCMS.Web.ExceptionHandler;
|
||||
using COMCMS.Web.Models;
|
||||
using Lib.Core.MiddlewareExtension.Extension;
|
||||
using Microsoft.AspNetCore.Authentication.Cookies;
|
||||
using Microsoft.AspNetCore.Authentication.JwtBearer;
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
@@ -20,6 +22,7 @@ using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
using Microsoft.Extensions.Options;
|
||||
using Microsoft.Extensions.WebEncoders;
|
||||
using Microsoft.IdentityModel.Tokens;
|
||||
using Newtonsoft.Json.Serialization;
|
||||
using Senparc.CO2NET;
|
||||
using Senparc.CO2NET.Cache;
|
||||
@@ -88,6 +91,28 @@ namespace COMCMS.Web
|
||||
//注册Cookie认证服务
|
||||
services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme).AddCookie();
|
||||
|
||||
// 配置JWT 验证
|
||||
var appSettingsSection = Configuration.GetSection("SystemSetting");
|
||||
var appSettings = appSettingsSection.Get<SystemSetting>();
|
||||
var key = Encoding.ASCII.GetBytes(appSettings.JwtSecret);
|
||||
services.AddAuthentication(x =>
|
||||
{
|
||||
x.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
|
||||
x.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme;
|
||||
})
|
||||
.AddJwtBearer(x =>
|
||||
{
|
||||
x.RequireHttpsMetadata = false;
|
||||
x.SaveToken = true;
|
||||
x.TokenValidationParameters = new TokenValidationParameters
|
||||
{
|
||||
ValidateIssuerSigningKey = true,
|
||||
IssuerSigningKey = new SymmetricSecurityKey(key),
|
||||
ValidateIssuer = false,
|
||||
ValidateAudience = false
|
||||
};
|
||||
});
|
||||
|
||||
// 设置表单内容限制
|
||||
services.Configure<FormOptions>(options =>
|
||||
{
|
||||
@@ -130,10 +155,13 @@ namespace COMCMS.Web
|
||||
app.UseHttpsRedirection();
|
||||
app.UseStaticFiles();
|
||||
app.UseCookiePolicy();
|
||||
app.UseAuthentication();
|
||||
app.UseStaticHttpContext();
|
||||
app.UseRouting();
|
||||
|
||||
|
||||
app.UseAuthentication();
|
||||
app.UseAuthorization();
|
||||
|
||||
app.UseEndpoints(endpoints =>
|
||||
{
|
||||
endpoints.MapControllerRoute(
|
||||
|
||||
Reference in New Issue
Block a user