加入收藏 | 设为首页 | 会员中心 | 我要投稿 鄂州站长网 (https://www.0711zz.com/)- 数据分析、网络、云渲染、应用安全、大数据!
当前位置: 首页 > 编程开发 > asp.Net > 正文

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

发布时间:2020-09-21 07:40:23 所属栏目:asp.Net 来源:互联网
导读:我正在研究在ASP.NET(MVC Core 1.0)中使用基于声明的授权.在设置ClaimsIdentity时,我提供了一个键/值字符串对列表来表示每个Claim.例: ListClaim claims = new ListClaim{ new Claim(UserID, user.ID), new Claim(Name, user.Name), new

我正在研究在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核心声明身份验证的最佳文章是here和here.截至本文,我们仍然在RC1中,因此一些细节可能会在最终版本之前发生变化.

(编辑:鄂州站长网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读