Following on from my previous blog on “Creating your own identity provider …” The following changes can be made to add in your own claims.
Firstly in the App_Data\CustomSecurityTokenService.cs file of your identity provider web site I changed the following code
outputIdentity.Claims.Add( new Claim( System.IdentityModel.Claims.ClaimTypes.Name, principal.Identity.Name ) );
if (principal.Identity.Name.Equals("Steve") == true)
outputIdentity.Claims.Add(new Claim(ClaimTypes.Role, "Administrator"));
outputIdentity.Claims.Add(new Claim(ClaimTypes.Role, "User"));
The first parameter of the Claim constructor needs to be in the format of a namespace and I added this one up as it was an internal name we are using.
The second parameter of the Claim constructor is the value you want to pass through.
Next go to the appfabric portal and add in the following rule to your STS provider. You need to make sure that the schema string you have in your code matches the Input Claim Type you added in your rule.
Now you should be passing through the Business claim to your website. To get access to the claim use the following code:
IClaimsPrincipal principal = (IClaimsPrincipal)Thread.CurrentPrincipal;
var business = "";
foreach (Claim claim in principal.Identities.Claims)
business = claim.Value;
// we have a claim value for School so lets display it
BusinessLabel.Text = business;
BusinessLabel.Text = "No business claim found";
Again, note that the claim type namespace is the same as you specified previously.
The following claims are passed through to my website: