- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在研究在 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, user.ID),
new Claim(ClaimTypes.Name, user.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?
如果您生成的 Claim
,则使用预定义的 ClaimTypes
之一也会修改 Type 属性。 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 Core 声明身份验证的最佳文章是 here和 here 。截至本文发布时,我们仍处于 RC1 阶段,因此在最终发布之前某些细节可能会发生变化。
关于c# - ClaimType 的 ASP.NET 要求,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36179662/
我已经将 IdentityServer3 作为独立的身份服务器运行。 我有一个单独的 MVC 客户端,它使用 Cookie 和 OpenIdConnect 进行身份验证。我正在尝试在其他方面设置声明转
我一直在查看各种 System.IdentityModel.Claims.ClaimTypes 属性 ( Class reference ),看看我的每个用户模型属性是否都有预定义类型。似乎除了城市之
我正在研究在 ASP.NET (MVC Core 1.0) 中使用基于声明的授权。设置 ClaimsIdentity 时,我提供了一个键/值字符串对列表来表示每个 Claim。示例: List cla
我正在开发一个新应用程序并使用 ASP.NET Identity,想知道是否有一种方法可以在 ClaimsIdentity 上强制显示特定的声明类型。到目前为止,这是我所拥有的。它可以工作,但似乎这是
我有一个可以为用户分配以下角色的应用程序: super 管理员 管理员 用户 一个用户可能分配了两个或多个角色,例如。 super 管理员和用户。我的应用程序使用声明,因此我也想通过声明来验证用户角色
我目前正在开发一个实现 Azure ACS 的项目。我已经掌握了基础知识,我注意到 Azure ACS 向我发送了 SAML 信息,其中包括 IdentityProvider 和 NameIdenti
我正在玩弄 .net 4.5 中的声明授权。这工作得很好。但我遇到了一个小问题。 我认为设置名称声明类型应该导致身份名称 我检查过 ident.NameClaimType 与 ClaimTypes.N
使用 ASP.NET Core 2.2 和 Identity Server 4 我有以下 Controller : [HttpGet("posts"), Authorize] public async
我有这样创建的 JwtToken: X509Certificate2 cert = certificateStore.Certificate; var now = Da
使用 Asp.Net Identity 允许您向用户添加声明。 System.Security.Claims.ClaimTypes 允许您从各种 ClaimType 中选择任何 ClaimType。
有没有办法向自定义策略 ClaimType 添加超链接?例如,如果我需要用户同意才能同意使用条款,我如何提供与复选框标签内嵌的使用条款的链接? 在我的自定义策略(基本 xml)中,我尝试添加以下内容:
使用 Asp.Net Identity 允许您向用户添加声明。 System.Security.Claims.ClaimTypes 允许您从各种 ClaimType 中选择任何 ClaimType。
我是一名优秀的程序员,十分优秀!