Claims Viewer Web Part

In this article we can explore the Claims Viewer Web Part.

About Web Part

I was working in a Claims enabled SharePoint Web Application where I felt the need of a Claims Viewer component which could display the current claims of the logged-in user.

Download

You can go the following location to get the web part:

https://sharepoint2013claimsviewer.codeplex.com/

Example

An example is displayed below.

image

Web Part

The above component is developed as a Web Part and requires Farm Solution for deployment. The C# code runs in the server-side and renders the claims values to the output.

Code

Following is the code which retrieves the claims.

protected void Page_Load(object sender, EventArgs e)

{

IClaimsPrincipal principal = Thread.CurrentPrincipal as IClaimsPrincipal;

IClaimsIdentity identity = principal.Identity as IClaimsIdentity;

IList<ClaimEntity> list = new List<ClaimEntity>();

foreach (Claim claim in identity.Claims)

list.Add(new ClaimEntity()

{

ClaimType = claim.ClaimType,

Value = claim.Value,

ValueType = claim.ValueType

});

RefreshGrid(list);

}

Once the user is logged in, the thread will contain the Claims Principal object. We can get the Claims from this object.

Each claim will have the following:

· Claim Type which is the pre-defined URL eg: http://schemas.xmlsoap.org/ws/2005/05/identity/claims/nameidentifier

· Claim Value which is the actual claim value eg: windows\administrator

image
You can use the References for articles on Installation of the Claims Viewer web part.

References

https://sharepoint2013claimsviewer.codeplex.com/

Summary

In this article we have explored the usage of Claims Viewer web part.

Leave a Reply

Your email address will not be published. Required fields are marked *