Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get ClaimsPrincipal from ADAL AuthenticationResult

I'm using Azure Active Directory Authentication Library to sign-in users in a WPF application. After call to AuthenticationContext.AcquireToken() I get AuthenticationResult with some UserInfo but it does not provide a ClaimsPrincipal which my application uses. Also System.Security.Claims.ClaimsPrincipal.Current returns only an empty principal object with no claims populated in it. How do I get the ClaimsPrincipal for the signed-in user?

like image 292
orad Avatar asked Feb 09 '16 22:02

orad


1 Answers

The AuthenticationResult.AccessToken is a JWT token that represents the user. You can use http://www.nuget.org/packages/System.IdentityModel.Tokens.Jwt/5.0.0-rc1-211161024 to read the token and create a claims principal. the api for the JwtSecurityTokenHandler.ValidateToken takes a TokenValidationParameters that can be used to scope validation.

All that said, depending on what you need (perhaps you don't need a ClaimsPrincipal), you might want to have a look at the AuthenticationResult.UserInfo property.

like image 100
Brent Schmaltz Avatar answered Oct 11 '22 18:10

Brent Schmaltz