I'm working through an exercise in Chapter 4.2 of the PDE book by Robert McOwen. I have derived that when $n=2$ and $a=1$, the Poisson integral formula can be represented by
$$u(r,\theta)=\frac{1-r^2}{2\pi}\int_0^{2\pi}\frac{g(\phi)d\phi}{1+r^2-2r\cos(\theta-\phi)}$$
Now, I'm trying to verify that
$$r^k\cos k\theta=\frac{1-r^2}{2\pi}\int_0^{2\pi}\frac{\cos (k\phi)d\phi}{1+r^2-2r\cos(\theta-\phi)}$$
where $k$ is an integer and $0\leq r < 1$.
I've previously derived that we can find $u(r,\theta)$ by the Fourier series representation
$$u(r,\theta)=a_0+\sum_{n=1}^{\infty}r^n(a_n \cos n\theta + b_n\sin n\theta)$$
But, I'm not sure why this implies that
$$r^k\cos k\theta=\frac{1-r^2}{2\pi}\int_0^{2\pi}\frac{\cos (k\phi)d\phi}{1+r^2-2r\cos(\theta-\phi)}$$
Is there a property of Fourier series that I can reference to show that
$$g(\phi)=\cos (k\phi)$$
and that
$$u(r,\theta)=\frac{1-r^2}{2\pi}\int_0^{2\pi}\frac{\cos (k\phi)d\phi}{1+r^2-2r\cos(\theta-\phi)}$$
Remember that $g(\theta)$ is the boundary condition for your PDE: that is, you want to find a function $u(r,\theta)$ solving $$\left\{ \begin{array}{cc} \Delta u = 0& \text{in } B(0,1)\\ u(1,\theta) = g(\theta)&\\ \end{array}\right.\tag{*}$$ The function $u$ given by the Poisson formula is the unique solution to the problem, so if we have any function solving $(*)$, then that function must be equal to the Poisson integral.
In particular, we notice that the function $u(r,\theta) = r^k\cos(k\theta)$ solves $(*)$ with $g(\theta) = \cos(k\theta)$ (this is just a computation). But, since the solution is unique, this means that $$r^k\cos(k\theta) = \frac{1-r^2}{2\pi}\int_0^{2\pi}\frac{\cos(k\phi)}{1+r^2-2r\cos(\theta-\phi)}\;d\phi$$
Notice in particular that we aren't declaring $g(\theta) = \cos (k\theta)$ always. What it is varies from problem to problem. However, if $g(\theta) = \cos(k\theta)$, then $u(r,\theta) =r^k \cos(k\theta)$ is the only solution to the PDE $(*)$.