Spaces:
Running
Running
Refactor Google OAuth2 callback to include state and scope parameters in the function signature and improve logging
Browse files- app/router/auth.py +5 -3
app/router/auth.py
CHANGED
@@ -1,8 +1,8 @@
|
|
1 |
"""Module for defining the main routes of the API."""
|
2 |
import os
|
3 |
import json
|
4 |
-
import logging
|
5 |
import pickle
|
|
|
6 |
from fastapi import APIRouter, Request
|
7 |
from fastapi.responses import JSONResponse
|
8 |
from google_auth_oauthlib.flow import InstalledAppFlow
|
@@ -45,7 +45,7 @@ async def get_auth_url():
|
|
45 |
return JSONResponse({"url": auth_url})
|
46 |
|
47 |
@router.get("/auth/google/callback")
|
48 |
-
async def google_callback(code: str, request: Request):
|
49 |
"""
|
50 |
Handles the Google OAuth2 callback by exchanging the authorization code for credentials,
|
51 |
retrieving the user's Gmail profile, and saving the credentials to a file.
|
@@ -67,7 +67,9 @@ async def google_callback(code: str, request: Request):
|
|
67 |
- json: Used to serialize and deserialize credentials.
|
68 |
- pickle: Used to save credentials to a file.
|
69 |
"""
|
70 |
-
|
|
|
|
|
71 |
flow = InstalledAppFlow.from_client_config(CLIENT_CONFIG, SCOPES)
|
72 |
flow.redirect_uri = REDIRECT_URI
|
73 |
flow.fetch_token(code=code)
|
|
|
1 |
"""Module for defining the main routes of the API."""
|
2 |
import os
|
3 |
import json
|
|
|
4 |
import pickle
|
5 |
+
from cv2 import log
|
6 |
from fastapi import APIRouter, Request
|
7 |
from fastapi.responses import JSONResponse
|
8 |
from google_auth_oauthlib.flow import InstalledAppFlow
|
|
|
45 |
return JSONResponse({"url": auth_url})
|
46 |
|
47 |
@router.get("/auth/google/callback")
|
48 |
+
async def google_callback(state: str, code: str, scope: str, request: Request):
|
49 |
"""
|
50 |
Handles the Google OAuth2 callback by exchanging the authorization code for credentials,
|
51 |
retrieving the user's Gmail profile, and saving the credentials to a file.
|
|
|
67 |
- json: Used to serialize and deserialize credentials.
|
68 |
- pickle: Used to save credentials to a file.
|
69 |
"""
|
70 |
+
print("state: ", state)
|
71 |
+
print("code: ", code)
|
72 |
+
print("scope: ", scope)
|
73 |
flow = InstalledAppFlow.from_client_config(CLIENT_CONFIG, SCOPES)
|
74 |
flow.redirect_uri = REDIRECT_URI
|
75 |
flow.fetch_token(code=code)
|