This might be a possible duplicate - please let me know if there is already a proof in another thread.
Consider the momentum operator on $\mathcal{L}^2[0,2\pi]$: $$P:\mathcal{D}\to\mathcal{L}^2:f\mapsto -i\frac{d}{dx}f\text{ with }\mathcal{D}:=\{f\in AC[0,2\pi]:f(0)=0=f(2\pi)\}$$
How do I prove that all selfadjoint extensions are given by: $$P_\theta:\mathcal{D}_\theta\to\mathcal{L}^2:f\mapsto -i\frac{d}{dx}f\text{ with }\mathcal{D}_\theta:=\{f\in AC[0,2\pi]:f(0)=e^{i\theta}f(2\pi)\}$$
I won't argue that the domain of $P$ is dense in $L^{2}[0,2\pi]$, even though it is.
Suppose that $g \in \mathcal{D}(P^{\star})$. Equivalently, there exists $l \in L^{2}$ such that $(Pf,g)=(f,l)$ for all $f \in \mathcal{D}(P)$. Because this must hold for all such $f$, then we may choose $$ f_{a,b,h,k}(t) = i\int_{0}^{t}\left[\frac{1}{h}\chi_{[a-h,a]}(u)-\frac{1}{k}\chi_{[b,b+k]}(u)\right]\,du $$ where $0 \le a-h < a \le b < b+k \le 2\pi$. By definition $f_{a,b,h,k} \in \mathcal{D}(P)$. Substituting $f_{a,b,h,k}$ into the adjoint relation gives $$ \frac{1}{h}\int_{a-h}^{a}\overline{g(u)}\,du-\frac{1}{k}\int_{b}^{b+k}\overline{g(u)}\,du = (f_{a,b,h,k},l). $$ As $h\downarrow 0$ and/or $k\downarrow 0$, it is easy to see that $f_{a,b,h,k}$ converges in $L^{2}$ (look at the graph.) So, the limits of the left side exist also. That means both the left- and right-hand derivatives of $$ G(x)=\int_{0}^{x}\overline{g(u)}\,du $$ exist at every $x \in (0,2\pi)$, and the two limits are equal because $f_{a,h,a,k}$ tends to $0$ in $L^{2}$ as $h,k\downarrow 0$. So $G$ has a derivative everywhere in $(0,2\pi)$ and $G'=\overline{g}$ a.e. by Lebesgue's differentiation theorem. It follows that, for almost every $a,b \in (0,2\pi)$, one has $$ \overline{g(a)}-\overline{g(b)}=(i\chi_{[a,b]},l) $$ The right side is continuous in $a$, $b$, which means that $g$ is equal a.e. to a continuous function $\tilde{g}$ on $[0,2\pi]$. I won't confuse the issue by using $\tilde{g}$--just change $g$ to be continuous on $[0,2\pi]$. Then the above gives $$ g(b)-g(a)=i\int_{a}^{b}l(u)\,du. $$ It follows that a general $g\in \mathcal{D}(P^{\star})$ can be assumed (after possible trivial modification) to be absolutely continuous on $[0,2\pi]$ with $g'=il$ a.e.. Thus $P^{\star}g=l=-ig'$. So the adjoint is what you expect it to be. Any such $g$ can be seen to be in the domain of $P^{\star}$ by using integration by parts. So this is a full characterization of $P^{\star}$; indeed, $g \in \mathcal{D}(P^{\star})$ iff $g$ is equal a.e. to a continuous function on $[0,2\pi]$ which is also absolutely continuous with $g'\in L^{2}[0,2\pi]$ (and $P^{\star}g = -ig'$.)
If $A$ is any selfadjoint extension of $P$, then $P \prec A=A^{\star} \prec P^{\star}$. The graph of $P$ is of co-dimension $2$ in the graph of $P^{\star}$ because, for $f \in \mathcal{D}(P^{\star})$, $$ f(x)-\frac{f(0)}{2\pi}(2\pi -x)-\frac{f(2\pi)}{2\pi}x \in \mathcal{D}(P). $$ So $A$ must be a co-dimension $1$ restriction of $P^{\star}$. Next consider $$ (P^{\star}f,g)-(f,P^{\star}g) = \int_{0}^{2\pi}(-if'\overline{g}-if\overline{g'})\,du = -i(f\overline{g})|_{0}^{2\pi} $$ First, we find all possible $\alpha$ and $\beta$ with $|\alpha|+|\beta|\ne 0$ such that adding $\alpha x+\beta(2\pi-x)$ to the domain of $P$ gives a symmetric operator $A$. We only have to check the above with $f=g=\alpha x+\beta(2\pi-x)$ because the above is $0$ if either $f$ or $g$ is in the domain of $P$. I believe this boils down to $|\alpha|=|\beta|$. This is equivalent to your stated condition for $\mathcal{D}_{\theta}$. And, you can directly verify from the above that this does give a selfadjoint $P_{\theta}$. Indeed, $P_{\theta}$ is symmetric, which gives $P_{\theta} \preceq P_{\theta}^{\star}$, which means that either (a) $P_{\theta}^{\star}=P_{\theta}$ or (b) $P_{\theta}^{\star}=P^{\star}$, but (b) is impossible because $P\prec P_{\theta}$ is strict and $P_{\theta}\preceq P_{\theta}^{\star}$ because of symmetry.