Quotient of an affine variety by a finite group I have worked through the proof of the statement that a quotient of an affine variety X always exists in case the group G acting on X is finite (see "Algebraic Geometry, a First Course" by Harris, page 124), and now I'm trying to show that this construction satisfies the universality property.
So I have $\pi : X \rightarrow Y$ surjective with Y being the quotient of X. I need to show that, given another variety Z and $f: X \rightarrow Z$ regular, f factors through Y iff it is a G invariant map, i.e. $f(p)=f(g(p)) \forall g \in G, p \in X$.
I tried to proof this via the respective coordinate rings: I have - by construction - an inclusion map $A(Y)=A(X)^G \hookrightarrow A(X)$ and the induced map $f^*: A(Z) \rightarrow A(X)$. Now, assuming for instance that f is G invariant, I would need to show that there exists $\varphi :A(Z) \rightarrow A(Y)$ making the diagram commutative so that I could take the induced map of $\varphi$ as a factorization of f. Am I on the right track here? And what about the other direction?
Thanks in advance.
 A: Let $A$ be a ring and let $G$ be a finite group with a morphism $G\to \mathrm{Aut}(A)$. Note that $G$ acts from the right on $X=\mathrm{Spec} A$. Consider the morphism $\pi:X\longrightarrow Y$, with $Y=\mathrm{Spec} A^G$, induced by the injection $A^G \subset A$.
Using that the category of affine schemes is (anti-)-equivalent to the category of rings, it is easy to see that $\pi:X\longrightarrow Y$ is the quotient for the action of $G$ in the category of affine schemes: every $G$-invariant morphism $f:X\to Z$ with $Z$ affine factors uniquely through $\pi$. In fact, this can be  easily deduced from the following obvious statement: any ring morphism $\varphi:R\to A$ such that for all $g$ in $G$ we have $g\varphi = \varphi$ factors uniquely through $A^G$.
So as you know, $\pi:X\to Y$ is the quotient for the action of $G$ in the category of schemes. But it's actually even better than that! The morphism $\pi:X\to  Y$ is the quotient for the action of $G$ in the category of locally ringed spaces. Let me sketch how you can prove this. 
Firstly, show that $\pi:X\to Y$ is the set-theoretical quotient map, i.e.,  $\pi$ induces a bijection between the $G$-orbits of $X$ and $Y$. This is the hard part. For example,
 given a prime ideal $\mathfrak{p}$ in $B=A^G$, you will need to show that $B_{\mathfrak{p}} = (A_{\mathfrak{p}})^G$. (The natural map $B_{\mathfrak{p}} \to A_{\mathfrak{p}}$ factors uniquely through a map $B_{\mathfrak{p}} \to (A_{\mathfrak{p}})^G$. It suffices to show that this map is surjective. Use the definition of the stalk and write it out.) Also, to conclude, suppose that we have two distinct orbits $x_1 G$ and $x_2 G$ of primes lying over $\mathfrak{p}$. Then, applying  the Chinese remainder theorem, you will that this is impossible.
So suppose that we have shown that $\pi:X\to Y$ is the set-theoretical quotient map. Then, it is easy to see that $Y$ has the quotient topology. In fact, $\pi$ is continuous and closed.
Now, to finish, you look at the natural morphism of sheaves $ \mathcal{O}_Y\to  (\pi_ast \mathcal{O}_X)^G$. This is an isomorphism. (You can check this is on the principal opens $D(b)$ of $Y$, with $b\in B$. But then this boils down to showing that $B_{b} \to (A_b)^G$ is an isomorphism. We already showed this above.)
So this is a really rough sketch of how I recall the proof. Let me know if you need some more details. 
