So the authorization request url is correct and it successfully redirects to redirect_url
which is /loginAuthorized
. I can plainly see that a code
is added as in
http://127.0.0.1:5000/loginAuthorized/?code=SOME_CODE`
but can't grab it on the code. When I print path
, it just prints loginAuthorized/
wihtout code
. I can ask users to manually copy paste code from url, but it will not be convenient so want to avoid asking that.
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&redirect_uri=http%3A%2F%2F127.0.0.1%3A5000%2F%2FloginAuthorized/&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("/<path:path>")
def loginAuthorized(path):
print('a')
print(path) # "loginAuthorized/" is printed, there is no code
print('b')
if __name__ == "__main__":
app.run()