Add more descriptive error logs when google auth token verification fails

This commit is contained in:
sabaimran 2024-12-17 15:18:38 -08:00
parent 60d55a83c4
commit ef99d8c28e

View file

@ -216,18 +216,27 @@ async def auth(request: Request):
base_url = str(request.base_url).rstrip("/")
redirect_uri = f"{base_url}{request.app.url_path_for('auth')}"
verified_data = requests.post(
"https://oauth2.googleapis.com/token",
headers={"Content-Type": "application/x-www-form-urlencoded"},
data={
payload = {
"code": code,
"client_id": os.environ["GOOGLE_CLIENT_ID"],
"client_secret": os.environ["GOOGLE_CLIENT_SECRET"],
"redirect_uri": redirect_uri,
"grant_type": "authorization_code",
},
}
verified_data = requests.post(
"https://oauth2.googleapis.com/token",
headers={"Content-Type": "application/x-www-form-urlencoded"},
data=payload,
)
if verified_data.status_code != 200:
logger.error(f"Token request failed: {verified_data.text}")
try:
error_json = verified_data.json()
logger.error(f"Error response JSON for Google verification: {error_json}")
except ValueError:
logger.error("Response content is not valid JSON")
verified_data.raise_for_status()
credential = verified_data.json().get("id_token")