WIF Claims Programming Model
ASP.NET and Windows Communication Foundation (WCF) developers ordinarily use the IIdentity and IPrincipal interfaces to work with the user’s identity information. In .NET 4.5, Windows Identity Foundation (WIF) has been integrated such that claims are now always present for any principal as illustrated in the following diagram:
In .NET 4.5, System.Security.Claims contains the new ClaimsPrincipal and ClaimsIdentity classes (see diagram above). All principals in .NET now derive from ClaimsPrincipal. All built-in identity classes, like FormsIdentity for ASP.NET and WindowsIdentity now derive from ClaimsIdentity. Similarly, all built-in principal classes like GenericPrincipal and WindowsPrincipal derive from ClaimsPrincipal.
A claim is represented by Claim class. This class has the following important properties:
-
Type represents the type of claim and is typically a URI. For example, the e-mail address claim is represented as http://schemas.microsoft.com/ws/2008/06/identity/claims/email.
-
Value contains the value of the claim and is represented as a string. For example, the e-mail address can be represented as “someone@contoso.com”.
-
ValueType represents the type of the claim value and is typically a URI. For example, the string type is represented as http://www.w3.org/2001/XMLSchema#string. The value type must be a QName according to the XML schema. The value should be of the format namespace#format to enable WIF to output a valid QName value. If the namespace is not a well-defined namespace, the generated XML probably cannot be schema validated, because there will not be a published XSD file for that namespace. The default value type is http://www.w3.org/2001/XMLSchema#string. Please see http://www.w3.org/2001/XMLSchema for well-known value types that you can use safely.
-
Issuer is the identifier of the security token service (STS) that issued the claim. This can be represented as URL of the STS or a name that represents the STS, such as https://sts1.contoso.com/sts.
-
OriginalIssuer is the identifier of the STS that originally issued the claim, regardless of how many STSs are in the chain. This is represented just like Issuer.
-
Subject is the subject whose identity is being examined. It contains a ClaimsIdentity.
-
Properties is a dictionary that lets the developer provide application-specific data to be transferred on the wire together with the other properties, and can be used for custom validation.
An important property of ClaimsIdentity is Actor. This property enables the delegation of credentials in a multi-tier system in which a middle tier acts as the client to make requests to a back-end service.
To access the current user’s set of claims in an RP application, use Thread.CurrentPrincipal.
The following code sample shows the usage of this method to get a System.Security.Claims.ClaimsIdentity:
ClaimsPrincipal claimsPrincipal = Thread.CurrentPrincipal as ClaimsPrincipal;
For more information, see System.Security.Claims.
WIF supports several combinations of authentication mechanisms out of the box. The following table lists the claims that WIF extracts from different token types.
|
Token Type |
Claim Generated |
Map To Windows Access Token |
|
SAML 1.1 |
|
In addition to the claims listed in “SAML 1.1”, except claims of type http://schemas.xmlsoap.org/ws/2005/05/identity/claims/name, Windows authentication related claims will be added and the identity will be represented by WindowsClaimsIdentity. |
|
SAML 2.0 |
Same as “SAML 1.1”. |
Same as “SAML 1.1 Mapped to Windows Account”. |
|
X509 |
|
|
|
UPN |
|
|
|
Windows (Kerberos or NTLM) |
|
|
|
RSA Key Pair |
|
|
|
Authentication Type |
URI emitted in “AuthenticationMethod” claim |
|
Password |
urn:oasis:names:tc:SAML:1.0:am:password |
|
Kerberos |
urn:ietf:rfc:1510 |
|
SecureRemotePassword |
urn:ietf:rfc:2945 |
|
TLSClient |
urn:ietf:rfc:2246 |
|
X509 |
urn:oasis:names:tc:SAML:1.0:am:X509-PKI |
|
PGP |
urn:oasis:names:tc:SAML:1.0:am:PGP |
|
Spki |
urn:oasis:names:tc:SAML:1.0:am:SPKI |
|
XmlDSig |
urn:ietf:rfc:3075 |
|
Unspecified |
urn:oasis:names:tc:SAML:1.0:am:unspecified |