views:

205

answers:

2

Hi

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);

A: 

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.

Venki
I tried your code but in my application.Below is the code I added to the application string alias = ((MicrosoftAdfsProxyRP.MicrosoftPrincipal)HttpContext.Current.User).Alias; Microsoft.IdentityModel.Claims.IClaimsPrincipal claimsPr = (IClaimsPrincipal)(HttpContext.Current.User); ClaimsIdentityCollection lst = claimsPr.Identities;I am gettting the following error Unable to cast object of type 'MicrosoftAdfsProxyRP.MicrosoftPrincipal' to type 'Microsoft.IdentityModel.Claims.IClaimsPrincipal'. Let me know any solution for this . Thanks in advance
stackuser1
+1  A: 

Hey stackuser1,

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

Andrew Arnott