In this answer I said that "it is left as an exercise to show that" $$\int\frac{M\cos^2u-(M-1)\sec^2u}{\sqrt{1-M\sin^2u}}\,du=(\tan u)\sqrt{1-M\sin^2u}+C\tag1$$ The original question asked for the derivation of a solution to an integral; the solution involves elliptic integrals. Because of the latter, I would ordinarily have the full power of elliptic integrals/functions at my disposal (i.e. Byrd and Friedman), but the OP said at the start
Yet again I might say I am very very rusty on my mathematics, but in this case I've never even heard of elliptic integrals up to the point I saw this paper.
And I did not want to scare the OP away by saying "oh, this is B&F XXX.XX, we have this and that". I wanted to be gentle.
However, I could not think of an easy way to justify the integral at the start of this question other than differentiating the solution I already knew. How could I solve $(1)$ from scratch in an elementary manner?
The integrand's numerator is$$\begin{align}M\cos^2u-(M-1)\sec^2u&=M-M\sin^2u+\sec^2u-M\sec^2u\\&=-M\sin^2u+\sec^2u-M\tan^2u\\&=-M\sin^2u+\sec^2u\cdot(1-M\sin^2u),\end{align}$$so the integrand is$$\frac{-M\sin u\cos u}{\sqrt{1-M\sin^2u}}\tan u+\sqrt{1-M\sin^2u}\sec^2u.$$Finish with the product rule.