Design: Google OAuth using AngularJS and Flask
<p>I am building a web application using AngularJS on the frontend and Python with Flask on the server side. I am trying to implement the OpenID/OAuth login feature following the documentation available on <a href="https://developers.google.com/identity/protocols/OpenIDConnect" rel="nofollow">google developers site</a>. I began by building the server side code first(where everything worked fine when tested using Postman), and started to work on frontend. Now, I have a feeling that the design I followed for adding this feature is really bad. Below is the problem I am facing:</p>

<p>Following the Google OAuth documentation, I have setup my server side flow somewhat like this:</p>

<p><strong>gAuth</strong>:
It is a function in my Flask app that will be invoked by a GET request from Angular when the user clicks on the Google signIn button.</p>

<p>It sends a GET request to the Google authorization endpoint to fetch the authorization code. The response to this request has got a text field which has an HTML code that shows the google login page. I am returning this to Angular(because that's where this function has been invoked from). Then Angular renders this on the browser for the user to enter credentials. Once the user enters credentials and authorizes my application, Google sends the auth code to another function in my app <strong>requestToken</strong> using a GET request, because that is the redirect_URI I am using for the Google OAuth. At this point, I am completely cut from Angular. Now requestToken sends a POST request to token endpoint of Google using the auth code in order to exchange it for an id_token. Now requestToken has the id_token and does what it is supposed to do with it. </p>

<p>I am returning a value of '1' from the requestToken function, but that goes to the Google code, because that is where the request to requestToken came from. </p>

<p>Now, the problem is how can I let the frontend know that everything went fine with OAuth and user must be redirected to the homepage. I want the return value of requestToken to go to Angular. I want to ask if that is possible, but my commonsense says that it is not possible. But, I am wondering if there is a way by which I can send a request from Flask to Angular. Any help is much appreciated.</p>

<p>I gave up with manual implementation. There is a ready to use lib: <a href="https://github.com/sahat/satellizer" rel="nofollow">Satellizer</a> as well as server implementation (for Python example see the docs).</p>

javascript python angularjs google-app-engine oauth