title: How do I extract code from redirected url? (OAuth 2.0, Flask)
body: <p>So the authorization request url is correct and it successfully redirects to <code>redirect_url</code> which is <code>/loginAuthorized</code>. I can plainly see that a <code>code</code> is added as in</p>
  
  <pre><code>http://127.0.0.1:5000/loginAuthorized/?code=SOME_CODE`
  </code></pre>
  
  <p>but can't grab it on the code. When I print <code>path</code>, it just prints <code>loginAuthorized/</code> wihtout <code>code</code>. I can ask users to manually copy paste code from url, but it will not be convenient so want to avoid asking that.</p>
  
  <pre><code>import re
  import requests
  from flask import Flask, render_template
  
  app = Flask(__name__)
  
  @app.route('/')
  def main():
  
      # encoded url with information needed to request an authorization
      url = "https://kauth.kakao.com/oauth/authorize?client_id=MY_CLIENT_ID&amp;redirect_uri=http%3A%2F%2F127.0.0.1%3A5000%2F%2FloginAuthorized/&amp;response_type=code"
      return render_template('index.html', request_url=url) 
  
  # If you authorize the service, it redirected to this url
  # Catch any url that has /loginAuthorized as its base
  @app.route("/loginAuthorized", defaults={"path": ""})
  @app.route("/&lt;path:path&gt;")
  def loginAuthorized(path):
      print('a')
      print(path)  # "loginAuthorized/" is printed, there is no code
      print('b')
  
  if __name__ == "__main__":
      app.run()
  </code></pre>