protected string GetClaimValue(ClaimKeys key)
 {
     if (((ClaimsIdentity)HttpContext.User.Identity).Claims.Count() > 0)
     {
         return(((ClaimsIdentity)HttpContext.User.Identity).FindFirst(key.ToString()).Value);
     }
     else
     {
         return(null);
     }
 }
Example #2
0
        /// <summary>
        /// Returns a claim value from the claims parameter using the ClaimsKey enumerator
        /// </summary>
        /// <param name="key"></param>
        /// <param name="claims"></param>
        /// <returns>String value of claim for given key</returns>
        public string GetClaimValue(ClaimKeys key, IEnumerable <Claim> claims)
        {
            var claim = claims.Where(c => c.Type == key.ToString()).FirstOrDefault();

            return(claim?.Value);
        }
        static string GetClaimValue(ClaimsIdentity claimsIdentity, ClaimKeys claimKey)
        {
            Claim claim = claimsIdentity.FindFirst(x => x.Type == claimKey.ToString());

            return(claim != null ? claim.Value : "");
        }