Logarithm and absolute value $$y' - y \tan x = 2x \sec x,\quad y(0)=0\tag1$$
integrating factor $= e^{-\int \tan x\ dx} = e^{\ln|\cos x|} = \cos x$
Can we write $|\cos x|$ as $\cos x$ above?
$$I.F. y = \int I.F.\ 2x\ \sec x\ dx\\(\cos x) y = \int \cos x \ 2x\ \sec x\ dx = \int 2x\ dx$$
If we had taken the integrating factor to be $ |\cos x|$, then in the above line $|\cos x|$ and $\sec x$ wouldn't have cancelled.
 A: 
$$y' - y \tan x = 2x \sec x\tag1$$$$\cdots\\I.F. y = \int I.F.\ 2x\ \sec x\ dx\\(\cos x) y = \int \cos x \ 2x\ \sec x\ dx = \int 2x\ dx$$
If we had taken the integrating factor to be $|\cos x|$, then in the above line $|\cos x|$ and $\sec x$ wouldn't have cancelled.

They would still have cancelled out. The absolute-value function just means that you have to break the equation up into two cases, negative $\cos x$ (here $|\cos x|=-\cos x$) and nonegative $\cos x=$ (here, $|\cos x|=\cos x$); notice that for the negative case, there are two extra minus signs in the equation, one on each side; so, the two cases then recombine into the original single case.

integrating factor $= e^{-\int \tan x\ dx} = e^{\ln|\cos x|} = \cos x$
Can we write $|\cos x|$ as $\cos x$ above?

I explained here that not only can you drop the absolute-value sign, you can even frivolously say that $$e^{\ln (-34\cos x)}$$ is an integrating factor of $(1).$ The $-34$ will cancel out for the same reason as above. So, to be pedantically accurate, it's not so much that the integrating factor of $(1)$ equals $\cos x,$ but that $\cos x$ is an integrating factor of $(1).$
A: Alternative : $\begin{align}&y' - y \tan x = 2x \sec x\\&y'\cos x-y\sin x=2x\\&(y\cos x) '=2x\\&y\cos x=x^2+C\end{align}$
$y(0) =0\implies C=0$
Hence solution : $y(x)=x^2 \sec x$
A: The solution is
$$y|\cos x|=\int 2x \sec x \times|\cos x|\, dx+c, c\in\mathbb R$$
$\implies y\times (\pm \cos x)=\pm\int 2x \sec x \times \cos x \, dx+c$
$\implies y=\pm\dfrac{ x^2}{(\pm \cos x)}\pm c \sec x$
$\implies y=x^2 \sec x +c \sec x, c\in\mathbb R$
