title: Account links successfully but access token shows invalid - Google OAuth
body: <p>I've been trying to implement Google OAuth service with the implicit flow for my Dialogflow account linking (Using this <a href="https://developers.google.com/actions/identity/google-sign-in-oauth?creation=no#implement_your_oauth_server" rel="noreferrer">documentation</a>) </p>
  
  <p>I've developed the code according to that document. It works fine when a user links his account and shows "you've successfully, linked your account with chatbot". </p>
  
  <p>But when I try to use the access token that I've generated in <strong>Step 3</strong> of that document, it says that the access token is not valid. Looks like it doesn't register with the Google service!</p>
  
  <p>Here is my code using which I've implemented it</p>
  
  <pre><code>import os
  import flask
  from flask import request, redirect
  import string
  import random
  from random import choice, randint
  import google_auth_oauthlib.flow
  from AES import AESCipher
  import json
  
  CLIENT_SECRETS_FILE = "client_secret.json"
  
  SCOPES = ['https://www.googleapis.com/auth/userinfo.profile', 'https://www.googleapis.com/auth/userinfo.email']
  app = flask.Flask(__name__)
  app.secret_key = 'SECRET_KEY'
  
  #
  # Actions on google call this function with client_id, redirect_uri, state, and response_type
  #
  @app.route('/auth')
  def authorize():
      flow = google_auth_oauthlib.flow.Flow.from_client_secrets_file(
          CLIENT_SECRETS_FILE, scopes=SCOPES)
  
      flow.redirect_uri = flask.url_for('oauth2callback', _external=True)
  
      print ("%%%%STATE", request.args["state"])
      authorization_url, state = flow.authorization_url(
          access_type='offline',
          include_granted_scopes='true')
  
      flask.session['state'] = request.args["state"]
      print ("IN AUTH STATE ", state)
  
      return flask.redirect(authorization_url)
  
  
  def get_user_id():
      min_char = 8
      max_char = 12
      allchar = string.ascii_letters + string.punctuation + string.digits
      password = "".join(choice(allchar) for x in range(randint(min_char, max_char)))
      return password
  
  
  @app.route('/oauth2callback')
  def oauth2callback():
      print ("### IN CALLBACK ###", request)
      state = flask.session['state']
  
      user_id = get_user_id()
      client_id = ''.join(random.sample("Google", len("Google")))
      key = ''.join(random.sample("JayPatel", len("JayPatel")))
      bytes_obj = {
          'user_id': user_id,
          'client_id': client_id
      }
      access_token = AESCipher("Jay").encrypt(json.dumps(bytes_obj))
      access_token = access_token.replace('+', 'p')
      access_token = access_token.replace('&amp;', '1')
  
      # My generated access_token looks like 
      # 6u2PeFcUtNmAblw5N3YAKSn7EC46xQVmgv3Rc8XK9sTW4xcgAxw1doRsvmgE/CC2qGUJ1x7XpNpdYvGes6qJHIEQSwvgEJt8hnYEUbm0qEA=
      print ("###### Access Token ", access_token)
      print ("###### State ", state)
  
      url = "https://oauth-redirect.googleusercontent.com/r/test-happierbot-4c514#access_token=" + access_token + "&amp;token_type=bearer&amp;state=" + state
  
      return redirect(url)
  
  
  if __name__ == '__main__':
      os.environ['OAUTHLIB_INSECURE_TRANSPORT'] = '1'
  
      app.run('localhost', 8080, debug=True)
  </code></pre>
  
  <p><strong>When I try to get the information</strong> using access_token by <code>https://www.googleapis.com/oauth2/v1/tokeninfo?access_token=my_generated_token</code> API, it gives </p>
  
  <pre><code>{
      "error": "invalid_token",
      "error_description": "Invalid Value"
  }
  </code></pre>
  
  <blockquote>
    <p><strong>Is there any other process to activate the access_token or am I</strong>
    <strong>missing any step?</strong></p>
  </blockquote>