Skip to content

Commit

Permalink
able to get the url that the frontend is running on for callback in a…
Browse files Browse the repository at this point in the history
…pp.py
  • Loading branch information
qianxuege committed Dec 23, 2024
1 parent 228fe58 commit 8810868
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions backend/api/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,18 @@ def create_text_indexes():

@app.route('/login')
def login():
auth_url, _ = flow.authorization_url(prompt='consent')
origin = request.headers.get('Origin')
if not origin:
return jsonify({"error": "Origin header missing"}), 400
auth_url, _ = flow.authorization_url(prompt='consent', state=origin)
return jsonify({"auth_url": auth_url})

@app.route('/callback')
def callback():
# Retrieve the origin from the state parameter
origin = request.args.get('state')
redirect_uri = origin + '/home'
print(redirect_uri)
flow.fetch_token(authorization_response=request.url)
credentials = flow.credentials
session['credentials'] = {
Expand All @@ -83,7 +90,7 @@ def callback():
'client_secret': credentials.client_secret,
'scopes': credentials.scopes,
}
return redirect("http://127.0.0.1:5173/home") # Redirect to React app
return redirect(redirect_uri) # Redirect to React app

@app.route('/get_user_calendar')
def get_user_calendar():
Expand Down

0 comments on commit 8810868

Please sign in to comment.