微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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中,因此一些细节可能会在最终版本之前发生变化.

原文地址:https://www.jb51.cc/aspnet/245588.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐