mirror of
https://gitee.com/ccnetcore/Yi
synced 2026-03-28 12:46:36 +08:00
添加jwt认证模块
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
using AspNetCore.Microsoft.AspNetCore.Hosting;
|
||||
using Yi.Framework.Authentication.JwtBearer;
|
||||
using Yi.Framework.Core.Autofac.Extensions;
|
||||
using Yi.Framework.Core.Autofac.Modules;
|
||||
using Yi.Framework.Core.Extensions;
|
||||
@@ -13,6 +14,12 @@ builder.WebHost.UseStartUrlsServer(builder.Configuration);
|
||||
//添加模块
|
||||
builder.UseYiModules(typeof(YiFrameworkWebModule));
|
||||
|
||||
builder.Services.AddAuthentication(YiJwtAuthenticationHandler.YiJwtSchemeName);
|
||||
|
||||
builder.Services.AddAuthentication(option =>
|
||||
{
|
||||
option.AddScheme<YiJwtAuthenticationHandler>(YiJwtAuthenticationHandler.YiJwtSchemeName, YiJwtAuthenticationHandler.YiJwtSchemeName);
|
||||
});
|
||||
//添加autofac模块,需要添加模块
|
||||
builder.Host.ConfigureAutoFacContainer(container =>
|
||||
{
|
||||
@@ -25,6 +32,9 @@ var t = app.Services.GetService<Test2Entity>();
|
||||
|
||||
//全局错误中间件,需要放在最早
|
||||
app.UseErrorHandlingServer();
|
||||
|
||||
app.UseAuthentication();
|
||||
app.UseAuthorization();
|
||||
app.MapControllers();
|
||||
|
||||
app.Run();
|
||||
|
||||
Reference in New Issue
Block a user