We present a contact invariant trajectory optimization formulation to synthesize motions for legged robotic systems. The method is capable of finding optimal trajectories subject to whole body dynamics with hard contacts. Contact switches are determined automatically. We make use of concepts from bilevel optimization to find gradients of the system dynamics including the constraint forces and subsequently solve the optimal control problem with the unconstrained iLQR algorithm. Our formulation achieves fast computation times and scales well with the number of contact points. The physical correctness of the produced trajectories is verified through experiments in simulation and on real hardware. We showcase our method on a single legged hopper for which jumping and forward hopping motions are synthesized with an arbitrary number of contact switches. The jumping trajectories can be tracked on the robot and allow it to safely liftoff and land.