mirror of
https://github.com/khoj-ai/khoj.git
synced 2024-12-22 20:28:09 +00:00
Add more descriptive error logs when google auth token verification fails
This commit is contained in:
parent
60d55a83c4
commit
ef99d8c28e
1 changed files with 17 additions and 8 deletions
|
@ -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")
|
||||
|
|
Loading…
Reference in a new issue