|
|
|
@ -1,6 +1,4 @@
|
|
|
|
|
|
|
|
|
|
using System.Security.Claims;
|
|
|
|
|
|
|
|
|
|
using AuthStudy.Authentication.Basic;
|
|
|
|
|
using AuthStudy.Authentication.Basic.Events;
|
|
|
|
|
using AuthStudy.Authentication.Browser;
|
|
|
|
@ -14,7 +12,8 @@ namespace AuthStudy.WebApp
|
|
|
|
|
WebApplicationBuilder builder = WebApplication.CreateBuilder(args);
|
|
|
|
|
|
|
|
|
|
// 添加服务到IoC容器
|
|
|
|
|
builder.Services.AddControllers();
|
|
|
|
|
builder.Services.AddControllers(); //这里已经调用过了基础的认证与授权方法
|
|
|
|
|
|
|
|
|
|
// Swagger 注册
|
|
|
|
|
builder.Services.AddSwaggerGen();
|
|
|
|
|
|
|
|
|
@ -23,7 +22,7 @@ namespace AuthStudy.WebApp
|
|
|
|
|
builder.Services.AddBrowserAuthentication
|
|
|
|
|
(
|
|
|
|
|
BrowserAuthenticationDefault.SchemeName,
|
|
|
|
|
BrowserAuthenticationDefault.DispayName,
|
|
|
|
|
BrowserAuthenticationDefault.DisplayName,
|
|
|
|
|
new BrowserAuthenticationOptions()
|
|
|
|
|
{
|
|
|
|
|
AllowBrowsers = new List<string>() { "Edge" }
|
|
|
|
@ -37,7 +36,7 @@ namespace AuthStudy.WebApp
|
|
|
|
|
option.AllowBrowsers = new List<string>() { "Edge", "Chrome", "Firefox" };
|
|
|
|
|
})
|
|
|
|
|
//基本认证
|
|
|
|
|
.AddBasic(options =>
|
|
|
|
|
.AddBasic(BasicAuthenticationDefaults.AuthenticationScheme,options =>
|
|
|
|
|
{
|
|
|
|
|
options.Realm = "Basic Authentication";
|
|
|
|
|
options.Events = new BasicAuthenticationEvents
|
|
|
|
@ -60,7 +59,8 @@ namespace AuthStudy.WebApp
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
})
|
|
|
|
|
;
|
|
|
|
|
|
|
|
|
|
//默认基类实现注册
|
|
|
|
|
|
|
|
|
|