Skip to content

Commit d76683a

Browse files
authored
Add error messages in auth_redirect endpoint (#494)
1 parent a07e8a4 commit d76683a

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

src/plombery/api/authentication.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,15 @@ async def get_current_user(request: Request):
8080

8181
@router.get("/redirect")
8282
async def auth_redirect(request: Request):
83-
token = await oauth_client.authorize_access_token(request)
84-
user = token["userinfo"]
83+
try:
84+
token = await oauth_client.authorize_access_token(request)
85+
except Exception as e:
86+
raise HTTPException(401, f"Unable to authenticate. Error: {str(e)}")
87+
88+
try:
89+
user = token["userinfo"]
90+
except:
91+
raise HTTPException(401, "Unable to authenticate. Error: No user info")
8592

8693
if user:
8794
request.session["user"] = dict(user)

0 commit comments

Comments
 (0)