A general method is presented for symplectic integration of particle orbit in a 3-dimensional magnetic field. The reference orbit in phase space is solved by eliminating the linear part of the Hamiltonian. The Hamiltonian flow can be obtained by the Lie algebraic techniques such as matrix maps for linear motion and integrable polynomials for nonlinear motion. Our method eases the difficult task of particle tracking through insertion devices with complex magnetic field configuration such as the elliptical-polarization undulator. It can also be applied to calculate the particle orbit through a dipole or a quadrupole to include the fringe field effects accurately.