title: Can't figure out how to implement Google Sign in with oAuth2
body: <p>I am trying to create a login function for a web application and have been following the guide set out here <a href="https://developers.google.com/identity/sign-in/web/server-side-flow" rel="nofollow">https://developers.google.com/identity/sign-in/web/server-side-flow</a></p>
  
  <p>I have followed the instructions mostly copying everything and replacing it with my information. I want to keep it as basic as possible so I can understand what is happening.</p>
  
  <p>Here is my Python application for the authentication. I think I have done the http request wrong, as I had to find other examples because it's not explained on the google website.
  The website should send the auth_code to <a href="http://localhost:5000/auth_code" rel="nofollow">http://localhost:5000/auth_code</a> and the web.py should listen for it and if it is successful print out the email. </p>
  
  <p><strong>web.py</strong></p>
  
  <pre><code>from apiclient import discovery
  import httplib2
  from oauth2client import client
  import json
  
  h = httplib2.Http(".cache")
  resp, content = h.request("http://localhost:5000/auth_code", "GET")
  auth_code = content
  print (auth_code)
  
  CLIENT_SECRET_FILE = '*****.apps.googleusercontent.com.json'
  
  credentials = client.credentials_from_clientsecrets_and_code(
      CLIENT_SECRET_FILE, ['https://www.googleapis.com/auth/drive.appdata', 'profile', 'email'],
      auth_code)
  
  http_auth = credentials.authorize(httplib2.Http())
  drive_service = discovery.build('drive', 'v3', http=http_auth)
  appfolder = drive_service.files().get(fileID='appfolder').execute()
  
  userid = credentials.id_token['sub']
  email = credentials.id_token['email']
  print (email)
  </code></pre>
  
  <p>This is the python app for serving the webpage.</p>
  
  <p><strong>host.py</strong></p>
  
  <pre><code>from flask import Flask, render_template, request
  
  app = Flask(__name__)
  
  @app.route('/') def index():
      return render_template('index.html')
  if __name__=="__main__":    app.run(debug=True)
  </code></pre>
  
  <p>This is the HTML for the webpage.</p>
  
  <pre><code>&lt;!-- The top of file index.html --&gt; &lt;html itemscope itemtype="http://schema.org/Article"&gt; &lt;head&gt;   &lt;!-- BEGIN Pre-requisites --&gt;   &lt;script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"&gt;   &lt;/script&gt;   &lt;script src="https://apis.google.com/js/client:platform.js?onload=start" async defer&gt;   &lt;/script&gt;   &lt;!-- END Pre-requisites --&gt;   &lt;!-- Continuing the &lt;head&gt; section --&gt;   &lt;script&gt;
      function start() {
        gapi.load('auth2', function() {
          auth2 = gapi.auth2.init({
            client_id: '****.apps.googleusercontent.com',
            // Scopes to request in addition to 'profile' and 'email'
            //scope: 'additional_scope'
          });
        });
      }   &lt;/script&gt; &lt;/head&gt; &lt;body&gt;   &lt;!-- ... --&gt;   &lt;!-- Add where you want your sign-in button to render --&gt; &lt;!-- Use an image that follows the branding guidelines in a real app --&gt; &lt;button id="signinButton"&gt;Sign in with Google&lt;/button&gt; &lt;script&gt;   $('#signinButton').click(function() {
      // signInCallback defined in step 6.
      auth2.grantOfflineAccess({'redirect_uri': 'postmessage'}).then(signInCallback);   }); &lt;/script&gt; &lt;script&gt; function signInCallback(authResult) {   if (authResult['code']) {
  
      // Hide the sign-in button now that the user is authorized, for example:
      $('#signinButton').attr('style', 'display: none');
  
      // Send the code to the server
      $.ajax({
        type: 'POST',
        url: 'http://localhost:5000/auth_code',
        contentType: 'application/octet-stream; charset=utf-8',
        success: function(result) {
          // Handle or verify the server response.
        },
        processData: false,
        data: authResult['code']
      });   } else {
      // There was an error.   } } &lt;/script&gt; &lt;/body&gt; &lt;/html&gt;
  </code></pre>