$$f^2-Xf=X+1.$$ I think that $\deg (f)\leq 1$, because if $\deg(f)>1$, then $\deg(f^2-Xf)>1.$
So, I define: $f=1+ax$ (because the polynomial $Xf$, doesn't have constant term.)
$$f^2-Xf=1+2aX+a^2X^2-X-aX^2=1+X$$ $$1+(2a-1)X+(a^2-a)X^2-X=1+X$$ Then $a=a^2\Rightarrow a=0,1$. Is it correct?
Hint: write it as $\,f^2-1- X(f+1)= 0 \iff (f+1)(f-X-1)=0\,$.
[ EDIT ] The following comments on OP's posted solution.
This presumably means that the constant term of $\,f^2\,$ on the LHS must match the $\,1\,$ on the RHS, which is correct. However, it does not imply that the constant term of $\,f\,$ itself must be $\,1\,$, but rather that it must be $\,\color{red}{\pm} 1\,$. This is where one of the solutions $\,f=-1\,$ is lost.
The red term has already been incorporated into $\,(2a-1)X\,$, so it shouldn't be there.
It is necessary, but not sufficient, that $\,a^2-a=0\,$. In fact, all coefficients must match, so $\,2a-1=1\,$ and $\,a^2-a=0\,$. The only solution of this system is $\,a=1\,$.
Then, to complete the proof along this line, the case $\,f=\color{red}{-1}+ax\,$ needs to be worked out as well.