Introduction
Custom Claims Provider issues and packages claims into security tokens which can be further used to give permission to the items in a customized way. Claims Augmentation enables an application to augment additional claims into the user token. Claims can be displayed in the people picker control through claims picking. In this article, I will explain how to create Custom Claims Provider in SharePoint 2013 using C# Server-Side Object Model.
Pre-Requisites
- Open Visual Studio.
- Open New Project dialog box. Expand Office/SharePoint node and then choose SharePoint Solutions.
![]()
- Choose the SharePoint 2013 – Empty Project template. Name the project as ClaimProviderProject.
![]()
- Choose the Deploy as a farm solution option button and click Finish.
![]()
- To create a Custom Claims Provider class file, right click ClaimProviderProject project -> Add -> New Item.
![]()
- Add the class file and name it as CustomClaimsProvider.cs.
Create Custom Claims Provider
- Inherit SPClaimProvider to the new class created by adding Microsoft.SharePoint.Administration.Claims reference.
![]()
- Add the fields for Claims Provider as Display Name, Internal Name, and People picker display name.
- #region FIELDS
- public
- const string ClaimsProviderDisplayName = "Custom Claims Provider";
- public
- const string ClaimsProviderInternalName = "CustomClaimsProvider";
- private
- const string PickerEntitySchemaDisplayName = "Custom Claims";
- #endregion FIELDS
- Add the properties for Display Name and Internal Name.
- #region PROPERTIES
- public virtual string ProviderDisplayName {
- get {
- return ClaimsProviderDisplayName;
- }
- }
- public virtual string ProviderInternalName {
- get {
- return ClaimsProviderInternalName;
- }
- }
- #endregion PROPERTIES
- Override the SPClaimProvider properties, as shown below.
- #region OVERRIDDENPROPERTIES
- public override string Name {
- get {
- return this.ProviderInternalName;
- }
- }
- public override bool SupportsEntityInformation {
- get {
- return true;
- }
- }
- public override bool SupportsHierarchy {
- get {
- return true;
- }
- }
- public override bool SupportsResolve {
- get {
- return true;
- }
- }
- public override bool SupportsSearch {
- get {
- return true;
- }
- }
- #endregion OVERRIDDENPROPERTIES
- Create the constructor for newly created class.
- #region CONSTRUCTOR
- public CustomClaimsProvider(string displayName): base(displayName) {}
- #endregion CONSTRUCTOR
- Override the SPClaimProvider methods as the following.
- Override the FillClaimTypes method to add your custom claims type.
- protected override void FillClaimTypes(List < string > claimTypes)
- {
-
- }
- Override the FillClaimValueTypes method to add your custom value type.
- protected override void FillClaimValueTypes(List < string > claimValueTypes)
- {
-
- }
- Override the FillClaimsForEntity method to add your custom entities.
- protected override void FillClaimsForEntity(Uri context, SPClaim entity, List < SPClaim > claims)
- {
-
- }
- Override the FillEntityTypes method to add your custom entities type.
- protected override void FillEntityTypes(List < string > entityTypes)
- {
- entityTypes.Add(SPClaimEntityTypes.FormsRole);
- }
- Override the FillResolve method to add your custom resolve claim.
- protected override void FillResolve(Uri context, string[] entityTypes, SPClaim resolveInput, List < Microsoft.SharePoint.WebControls.PickerEntity > resolved)
- {
-
-
-
- }
- protected override void FillResolve(Uri context, string[] entityTypes, string resolveInput, List < Microsoft.SharePoint.WebControls.PickerEntity > resolved) {
-
-
-
- }
- Override the FillSchema method to add your custom schemas.
- protected override void FillSchema(Microsoft.SharePoint.WebControls.SPProviderSchema schema)
- {
-
- schema.AddSchemaElement(new SPSchemaElement(PeopleEditorEntityDataKeys.DisplayName, PickerEntitySchemaDisplayName, SPSchemaElementType.Both));
- }
-
- Override the FillSearch method to add your custom search claim.
- protected override void FillSearch(Uri context, string[] entityTypes, string searchPattern, string hierarchyNodeID, int maxCount, Microsoft.SharePoint.WebControls.SPProviderHierarchyTree searchTree)
- {
-
-
-
-
- }
- Add the SharePoint Feature to this project and set it as Farm level.
![]()
- Deploy this solution to the site.
- Activate the custom Claims Provider using Windows PowerShell script.
- Set the IsEnabled to True for the Claim Provider.
- Add provider association to the Web Application.
17. Check if the custom Claims Provider is populated in the assigning permission to an item.
![]()
Summary
Thus, you have learned how to create Custom Claims Provider in SharePoint 2013 using C# Server-Side Object Model.