How do I get other claims of the user using ADFS?

2019-07-24 17:36发布

I am able to authenticate the user using ADFS and succeded in getting the user alias using the below statement. Since some time, i am looking for a way in getting the other claims of the authenticated user, like email, name, roles, username etc.

Any help on this would be appreciated.

string alias = ((MicrosoftAdfsProxyRP.MicrosoftPrincipal)HttpContext.Current.User).Alias;

Response.Write (alias);

3条回答
我只想做你的唯一
2楼-- · 2019-07-24 18:17

The Claims way of getting the other claims is as follows.

IClaimsPrincipal claimsPr = (IClaimsPrincipal)(HttpContext.Current.User) From the claims principle you can get the ClaimsIdentityCollection through the IClaimsIdentity.

Get the IClaimsIdentity from the claimsPr.Identifies.

Then inspect all the claims present in the IClaimsIdentity using the Claims property.

查看更多
老娘就宠你
3楼-- · 2019-07-24 18:19

You're asking the world a question about an internal Microsoft service and interface. Try emailing the msftadfsproxydisc alias with your question.

查看更多
我想做一个坏孩纸
4楼-- · 2019-07-24 18:33

Have a look at How to: Access Claims in an ASP.NET Page.

Just in case the link disappears, the key is:

void Page_Load(object sender, EventArgs e)
{
    // Cast the Thread.CurrentPrincipal
    IClaimsPrincipal icp = Thread.CurrentPrincipal as IClaimsPrincipal;

    // Access IClaimsIdentity which contains claims
    IClaimsIdentity claimsIdentity = (IClaimsIdentity)icp.Identity;

    // Access claims
    foreach(Claim claim in claimsIdentity.Claims)
    {
      Response.Write(claim.ClaimType) + "<BR>";
      Response.Write(claim.Value) + "<BR>";
      Response.Write(claim.ValueType) + "<BR>";
    }
}
查看更多
登录 后发表回答