增加功能:swagger网页增加授权中间件

This commit is contained in:
Argo-MacBookPro 2018-10-24 20:12:11 +08:00
parent 68b5009e97
commit bbed98b4ae
1 changed files with 111 additions and 102 deletions

View File

@ -8,6 +8,7 @@ using Longbow.Data;
using Longbow.Logging; using Longbow.Logging;
using Longbow.Web; using Longbow.Web;
using Longbow.Web.SignalR; using Longbow.Web.SignalR;
using Microsoft.AspNetCore.Authentication;
using Microsoft.AspNetCore.Authentication.Cookies; using Microsoft.AspNetCore.Authentication.Cookies;
using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.DataProtection; using Microsoft.AspNetCore.DataProtection;
@ -123,6 +124,14 @@ namespace Bootstrap.Admin
name: "default", name: "default",
template: "{controller=Home}/{action=Index}/{id?}"); template: "{controller=Home}/{action=Index}/{id?}");
}); });
app.UseWhen(context => context.Request.Path == "/swagger/index.html", builder =>
{
builder.Use(async (context, next) =>
{
if (!context.User.Identity.IsAuthenticated) await context.ChallengeAsync();
else await next();
});
});
app.UseSwagger(); app.UseSwagger();
app.UseSwaggerUI(c => app.UseSwaggerUI(c =>
{ {