José Figueroa-O'Farrill has already pointed out one necessary condition, namely that your connection must be flat. The remaining condition is that the monodromy should be trivial. In what follows $X$ is any connected smooth manifold, not necessarily a surface, and $G$ is any Lie group.
Let's first consider the analogous situation when $G$ is replaced by $\mathbb{R}$. You can think of a one-form $\omega\in \Omega^1(X;\mathfrak{g})$ as potentially being the derivative of a map $X\to G$, just as a one-form $\eta\in \Omega^1(X;\mathbb{R})$ is potentially the derivative of a map $X\to \mathbb{R}$. We want to know when these really are the derivative of some map, i.e. when we can integrate these forms. (You mentioned the exponential map, but I think integration is the right metaphor here.)
There is a local obstruction, namely that if $\eta$ is to be integrable (meaning $\eta=df$ for some $f$) it must be closed, meaning $d\eta=0$; the Poincaré lemma tells us this is a sufficient condition for $\eta$ to be locally integrable. Then there is also a global condition, that the integral of $\eta$ around every closed loop must be 0 (unlike $d\theta$ on the circle, which has integral $2\pi$); Stokes' theorem tells us this is a necessary condition for $\eta$ to be globally integrable. If we have these conditions, recovering the map $f$ from $\eta$ is easy; just write $f(p)=\int_\ast^p \eta$, which is well-defined by the above two conditions.
Now let's try to do the same for $\mathfrak{g}$-valued one-forms. Start with a connection on the trivial $G$-bundle $X\times G$ with connection form $\omega\in \Omega^1(X;\mathfrak{g})$. We've talked about the connection being flat, which means that $d\omega+\frac{1}{2}[\omega,\omega]=0$; but what does that have to do with flatness or integrability? Well, you can show that $d\omega+\frac{1}{2}[\omega,\omega]$ measures the Lie bracket of two horizontal vector fields, or rather measures the vertical part of the Lie bracket. Thus if this vanishes, the bracket of two horizontal vector fields is horizontal. By the Frobenius integrability theorem, this implies that the horizontal distribution of the connection is integrable; another way to say this is that parallel transport is locally well-defined. Now pick a basepoint $\ast$ and restrict your attention to a small neighborhood $U$ of $\ast$. Since parallel transport is well-defined on $U$, we get a function $T\colon U\to G$ by saying that the parallel transport from $\ast$ to $u$ (along any path) is multiplication by $T(u)$.
Key point: if you pull back the tautological form on $G$ by this "parallel transport" map $T$, the form you get is the same as your original $\omega$!
What this tells us is that if a flat connection on $X\times G$ comes from a map $f:X\to G$, then you can recover $f$ by looking at the parallel transport of the connection. (The analogue is that if $\eta=f^\ast(dx)$ for some $f\colon X\to \mathbb{R}$, you can recover $f$ by integrating $\eta$, also known as the fundamental theorem of calculus.) Thus flatness, in the form of the Maurer-Cartan equation, is the local obstruction to integrability; here the Frobenius integrability theorem plays the role that the Poincaré lemma does in the real case. To prove the key point is really just a matter of definitions: think about the correspondence between a connection, its connection form, and its parallel transport.
In particular, this tells us that parallel transport must be not just locally well-defined, but globally well-defined (meaning independent of the path), since transport along any path from $\ast$ to $p$ is always multiplication by $f(p)\in G$. The monodromy of a flat connection is the map $\pi_1(X,\ast)\to G$ which sends a loop to the parallel transport around that loop, and so another way to say "parallel transport is globally well-defined" is that the monodromy is trivial.
This can all be summed up by saying that if $X$ is simply connected, we have an on-the-nose bijection $C^\infty(X,G)\longleftrightarrow \{\omega\in \Omega^1(X;\mathfrak{g})\vert d\omega+\frac{1}{2}[\omega,\omega]=0\}$. (Here on the left we assume the maps take the basepoint $\ast\in X$ to $1\in G$.) If $X$ has fundamental group, we need to add on the right side the additional condition that the monodromy of $\omega$ be 0. This is hard to write down just in terms of $\omega$, but for the corresponding connection it is just that parallel transport is totally path-independent.