在此处阅读文档:
然后遍历那些文档,选项类等中的所有扩展名和方法签名。似乎下面的(草稿)代码将用于设置我自己的自定义令牌身份验证。
# Make an options class called MyTokenOptions derive from AuthenticationSchemeOptions.
# Make my own handler and scheme classes (omitted) and new them up.
var handler = new MyTokenHandler();
var tokenScheme = new MyAuthenticationScheme("MyTokenV1", "My Encrypted Token v1", handler);
# Now configure my classes with ASP.NET Core.
services
.AddAuthentication(options =>
{
options.DefaultAuthenticateScheme = tokenScheme;
})
.AddScheme<MyTokenOptions,MyTokenHandler>("MyTokenV1", myOptions =>
{
myOptions.AllowAnonymous = false;
});
但是,制作自己的中间件组件并从标头读取令牌,构建主体并设置httpContext.User = myClaimsPrincipal
并返回,或者设置401并使管道短路似乎更简单。
我需要做所有文档中难以置信的复杂事情吗?