2017-06-01 88 views
2

因为我想将自定义声明添加到我的应用程序中,我检查了ClaimTypes的源代码(使用JetBrains反编译器进行反编译)。这是它的一块:索赔类型的网址是什么

namespace System.Security.Claims 
{ 
    /// <summary>Defines constants for the well-known claim types that can be assigned to a subject. This class cannot be inherited.</summary> 
    [ComVisible(false)] 
    public static class ClaimTypes 
    { 
    internal const string ClaimTypeNamespace = "http://schemas.microsoft.com/ws/2008/06/identity/claims"; 
    /// <summary>The URI for a claim that specifies the instant at which an entity was authenticated; http://schemas.microsoft.com/ws/2008/06/identity/claims/authenticationinstant.</summary> 
    public const string AuthenticationInstant = "http://schemas.microsoft.com/ws/2008/06/identity/claims/authenticationinstant"; 
    /// <summary>The URI for a claim that specifies the method with which an entity was authenticated; http://schemas.microsoft.com/ws/2008/06/identity/claims/authenticationmethod.</summary> 
    public const string AuthenticationMethod = "http://schemas.microsoft.com/ws/2008/06/identity/claims/authenticationmethod"; 
    /// <summary>The URI for a claim that specifies the cookie path; http://schemas.microsoft.com/ws/2008/06/identity/claims/cookiepath.</summary> 
    public const string CookiePath = "http://schemas.microsoft.com/ws/2008/06/identity/claims/cookiepath"; 
    /// <summary>The URI for a claim that specifies the deny-only primary SID on an entity; http://schemas.microsoft.com/ws/2008/06/identity/claims/denyonlyprimarysid. A deny-only SID denies the specified entity to a securable object.</summary> 
    public const string DenyOnlyPrimarySid = "http://schemas.microsoft.com/ws/2008/06/identity/claims/denyonlyprimarysid"; 
    /// <summary>The URI for a claim that specifies the deny-only primary group SID on an entity; http://schemas.microsoft.com/ws/2008/06/identity/claims/denyonlyprimarygroupsid. A deny-only SID denies the specified entity to a securable object.</summary> 
    public const string DenyOnlyPrimaryGroupSid = "http://schemas.microsoft.com/ws/2008/06/identity/claims/denyonlyprimarygroupsid"; 

我的问题是(我希望它不是太傻),什么网址?他们在别的地方用过吗?当我尝试打开一个URL时,我的资源管理器显示该网站未找到。所以我认为没有xml-schema或其他东西。 如果我添加了我的自定义声明,是否还需要添加类似这些URL的内容?

回答

2

这些是ClaimTypes,它表示实体可以声明的预定义类型的声明。你提到的是从WIF,这里是IdentityModel ClaimTypes。

已知的索赔类型会自动反序列化到上下文中。像http://schemas.microsoft.com/ws/2008/06/identity/claims/role作为角色添加到user.roles集合(用于IsInRole)。

所以类型不是随机的,而是按规格。你可以添加你自己的类型。这可以是任何字符串,但也可以使用相同的格式。

假设你添加客户编号权利要求,那么你就需要通过claimtype="CustomerId"查询声明集合,或者您定义的URI(比如:http://schemas/mycompany.com/2017/06/identity/CustomerId)。

您可以通过代码或通过在Identity.Claims表中插入记录添加声明。

+1

你是不是指'http://schemas.mycompany ...'? – xr280xr