Ejemplo n.º 1
0
        public bool ValidateToken(string token, string login)
        {
            login = null;

            var _simplePrinciple = JwtManagerHelper.GetPrincipal(token);
            var _identity        = _simplePrinciple?.Identity as ClaimsIdentity;

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

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

            var _usernameClaim = _identity.FindFirst(ClaimTypes.Name);

            login = _usernameClaim?.Value;

            if (string.IsNullOrEmpty(login))
            {
                return(false);
            }
            else
            {
                return(true);
            }

            throw new HttpResponseException(HttpStatusCode.Unauthorized);
        }
Ejemplo n.º 2
0
        private bool ValidateToken(string token, out string login)
        {
            login = null;

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

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

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

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

            login = usernameClaim?.Value;

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

            return(ValidateLogin(login));
        }
Ejemplo n.º 3
0
        public string GenerateToken(string login, string senha)
        {
            if (CheckUser(login, senha))
            {
                return(JwtManagerHelper.GenerateToken(login));
            }

            throw new HttpResponseException(HttpStatusCode.Unauthorized);
        }