mirror of
https://github.com/open-webui/open-webui
synced 2025-05-29 09:42:12 +00:00
refac: add better logging for oauth errors
This commit is contained in:
parent
981f384154
commit
99e7b328a4
@ -1883,17 +1883,19 @@ async def oauth_callback(provider: str, request: Request, response: Response):
|
|||||||
try:
|
try:
|
||||||
token = await client.authorize_access_token(request)
|
token = await client.authorize_access_token(request)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
log.error(f"OAuth callback error: {e}")
|
log.warning(f"OAuth callback error: {e}")
|
||||||
raise HTTPException(400, detail=ERROR_MESSAGES.INVALID_CRED)
|
raise HTTPException(400, detail=ERROR_MESSAGES.INVALID_CRED)
|
||||||
user_data: UserInfo = token["userinfo"]
|
user_data: UserInfo = token["userinfo"]
|
||||||
|
|
||||||
sub = user_data.get("sub")
|
sub = user_data.get("sub")
|
||||||
if not sub:
|
if not sub:
|
||||||
|
log.warning(f"OAuth callback failed, sub is missing: {user_data}")
|
||||||
raise HTTPException(400, detail=ERROR_MESSAGES.INVALID_CRED)
|
raise HTTPException(400, detail=ERROR_MESSAGES.INVALID_CRED)
|
||||||
provider_sub = f"{provider}@{sub}"
|
provider_sub = f"{provider}@{sub}"
|
||||||
email = user_data.get("email", "").lower()
|
email = user_data.get("email", "").lower()
|
||||||
# We currently mandate that email addresses are provided
|
# We currently mandate that email addresses are provided
|
||||||
if not email:
|
if not email:
|
||||||
|
log.warning(f"OAuth callback failed, email is missing: {user_data}")
|
||||||
raise HTTPException(400, detail=ERROR_MESSAGES.INVALID_CRED)
|
raise HTTPException(400, detail=ERROR_MESSAGES.INVALID_CRED)
|
||||||
|
|
||||||
# Check if the user exists
|
# Check if the user exists
|
||||||
@ -1958,7 +1960,9 @@ async def oauth_callback(provider: str, request: Request, response: Response):
|
|||||||
},
|
},
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
raise HTTPException(400, detail=ERROR_MESSAGES.INVALID_CRED)
|
raise HTTPException(
|
||||||
|
status.HTTP_403_FORBIDDEN, detail=ERROR_MESSAGES.ACCESS_PROHIBITED
|
||||||
|
)
|
||||||
|
|
||||||
jwt_token = create_token(
|
jwt_token = create_token(
|
||||||
data={"id": user.id},
|
data={"id": user.id},
|
||||||
|
Loading…
Reference in New Issue
Block a user