asp.net-core – ClaimTypes的ASP.NET要求

我正在研究在ASP.NET(MVC Core 1.0)中使用基于声明的授权.在设置ClaimsIdentity时,我提供了一个键/值字符串对列表来表示每个Claim.例:
List<Claim> claims = new List<Claim>
{
    new Claim("UserID",user.ID),new Claim("Name",user.Name),new Claim("Role","basic")
};

我的理解是我可以使用我想要的任何键/值.但是我注意到ClaimsType class上有一些预定义的键可用.因此,我可能会使用其中一些预定义的键:

List<Claim> claims = new List<Claim>
{
    new Claim(ClaimTypes.Sid,new Claim(ClaimTypes.Name,new Claim(ClaimTypes.Role,"basic")
};

问题:

>如果我使用预定义的密钥,是否有关于分配给每个密钥的实际值的规则/限制,还是应用程序定义的?例如,可以在ClaimTypes.Sid​​中粘贴数据库主键,还是ASP.NET对ClaimTypes.Sid​​应包含的内容有一定的期望?
>是否需要任何ClaimTypes,还是完全由应用程序决定包含或不包含哪些内容?我想,答案可能取决于我将与之交互的特定第三方身份验证服务,但是如何使用不包含任何第三方身份验证的自包含ASP.NET项目的简单情况. ASP.NET本身是否有任何要求?

任何与使用特定键/值的要求和/或最佳实践的链接都将受到赞赏.

解决方法

If I use the pre-defined keys,are there any rules/restrictions
regarding the actual values assigned to each key,or is it application
defined? For example,is it OK to stick a database primary key in
ClaimTypes.Sid,or does ASP.NET have certain expectations of what
ClaimTypes.Sid should contain?

使用其中一个预定义的ClaimTypes也会修改Type属性(如果生成的Claim). You can find a list of these types here.据我所知,您可以自由地将数据库ID放入ClaimTypes.Sid​​,但我强烈建议您使用自己的名称调用它.

Are there any ClaimTypes that are required,or is it completely up to
the application to decide what to include or not include? I imagine
the answer may depend on specific third-party authentication services
I would interact with,but how about the simple case of a
self-contained ASP.NET project that does not use any third-party
authentication. Does ASP.NET itself have any requirements?

假设没有第三方,您可以决定什么是必需的和不需要的.请记住,如果您将声明存储在Cookie(而非第三方来源)中,则您的空间有限; cookies cannot be larger than 4096 bytes in total.

到目前为止,我发现的ASP.NET核心声明身份验证的最佳文章herehere.截至本文,我们仍然在RC1中,因此一些细节可能会在最终版本之前发生变化.

相关文章

### 创建一个gRPC服务项目(grpc服务端)和一个 webapi项目(...
一、SiganlR 使用的协议类型 1.websocket即时通讯协议 2.Ser...
.Net 6 WebApi 项目 在Linux系统上 打包成Docker镜像,发布为...
一、 PD简介PowerDesigner 是一个集所有现代建模技术于一身的...
一、存储过程 存储过程就像数据库中运行的方法(函数) 优点:...
一、Ueditor的下载 1、百度编辑器下载地址:http://ueditor....