示例#1
0
        private static bool ValidateToken(string token, out string username)
        {
            username = null;

            var simplePrinciple = JwtUtil.GetPrincipal(token);
            var identity        = simplePrinciple?.Identity as ClaimsIdentity;

            if (identity == null)
            {
                return(false);
            }

            if (!identity.IsAuthenticated)
            {
                return(false);
            }

            var usernameClaim = identity.FindFirst(ClaimTypes.Name);

            username = usernameClaim?.Value;

            if (string.IsNullOrEmpty(username))
            {
                return(false);
            }

            // More validate to check whether username exists in system

            return(true);
        }