Exemplo n.º 1
0
        private bool IsvalidToken(string phone, string userId, string token)
        {
            try
            {
                var principal = tokenManager.GetPrincipal(token, out var securityToken);
                if (principal == null)
                {
                    return(false);
                }

                if (principal.Identity is ClaimsIdentity identity)
                {
                    var userClaim    = identity.FindFirst(ClaimTypes.MobilePhone);
                    var userIdClainm = identity.FindFirst(ClaimTypes.NameIdentifier);

                    if (userClaim?.Value == phone && userIdClainm?.Value == userId)
                    {
                        if (securityToken != null && securityToken.ValidTo.Date < DateTime.Now.Date)
                        {
                            throw new SecurityTokenExpiredException();
                        }
                        return(true);
                    }
                }
                return(false);
            }
            catch (Exception e)
            {
                throw e;
            }
        }
Exemplo n.º 2
0
        private bool IsvalidToken(string email, string token)
        {
            try
            {
                var principal = tokenManager.GetPrincipal(token, out var securityToken);
                if (principal == null)
                {
                    return(false);
                }

                if (principal.Identity is ClaimsIdentity identity)
                {
                    var userClaim = identity.FindFirst(ClaimTypes.Email);
                    if (userClaim?.Value == email)
                    {
                        if (securityToken != null && securityToken.ValidTo.Date < DateTime.Now.Date)
                        {
                            throw new SecurityTokenExpiredException();
                        }
                        return(true);
                    }
                }
                return(false);
            }
            catch (Exception e)
            {
                throw e;
            }
        }