From a9712226bace6222d0e14ddcaa2e05f64b0ef992 Mon Sep 17 00:00:00 2001 From: Mawoka Date: Wed, 15 Jun 2022 17:38:42 +0200 Subject: [PATCH] :goal_net: Caught an error in OAuth --- classquiz/oauth/github.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/classquiz/oauth/github.py b/classquiz/oauth/github.py index 6e8c91f..873ea24 100644 --- a/classquiz/oauth/github.py +++ b/classquiz/oauth/github.py @@ -1,3 +1,4 @@ +import authlib.integrations.base_client from fastapi import APIRouter, Request, HTTPException, Response from classquiz.config import settings @@ -86,7 +87,10 @@ async def auth(request: Request, response: Response): if rememberme_token is not None: return await rememberme_check(rememberme_token=rememberme_token, response=response) oauth = init_oauth() - token = await oauth.github.authorize_access_token(request) + try: + token = await oauth.github.authorize_access_token(request) + except authlib.integrations.base_client.OAuthError: + raise HTTPException(status_code=401, detail="The OAuth didn't work! :(") resp = await oauth.github.get("user", token=token) user_data = GitHubOauthResponse(**resp.json()) user_in_db = await User.objects.get_or_none(email=user_data.email)