internal AzureUserData GetCurrentUserInternal(JwtSecurityToken pToken = null) { if (pToken == null && (!IsCurrentUserAuthorized() || JwtIdToken == null)) { return(null); } var claims = JwtIdToken.Claims.ToArray(); EnsureClaimExists(claims, FirstNameClaimName); EnsureClaimExists(claims, LastNameClaimName); EnsureClaimExists(claims, EmailClaimName); EnsureClaimExists(claims, UserIdClaim); EnsureClaimExists(claims, "sub"); // we need this claim to make calls to AAD Graph var user = new AzureUserData() { AzureFirstName = claims.FirstOrDefault(x => x.Type == FirstNameClaimName)?.Value, AzureLastName = claims.FirstOrDefault(x => x.Type == LastNameClaimName)?.Value, Email = claims.FirstOrDefault(x => x.Type == EmailClaimName)?.Value, Id = claims.FirstOrDefault(x => x.Type == UserIdClaim).Value }; user.AzureDisplayName = $"{user.AzureFirstName} {user.AzureLastName}"; return(user); }
private AzureUserData GetCurrentUserInternal(JwtSecurityToken pToken = null) { if (pToken == null && (!IsCurrentUserAuthorized() || JwtIdToken == null)) { return(null); } var claims = JwtIdToken.Claims.ToArray(); EnsureClaimExists(claims, JwtRegisteredClaimNames.GivenName); EnsureClaimExists(claims, JwtRegisteredClaimNames.FamilyName); EnsureClaimExists(claims, "emails"); EnsureClaimExists(claims, "sub"); var user = new AzureUserData() { AzureFirstName = claims.FirstOrDefault(x => x.Type == JwtRegisteredClaimNames.GivenName)?.Value, AzureLastName = claims.FirstOrDefault(x => x.Type == JwtRegisteredClaimNames.FamilyName)?.Value, Email = claims.FirstOrDefault(x => x.Type == "emails")?.Value, Id = claims.FirstOrDefault(x => x.Type == "sub").Value }; user.AzureDisplayName = $"{user.AzureFirstName} {user.AzureLastName}"; return(user); }