Skip to content

Commit

Permalink
Update fastapi.py
Browse files Browse the repository at this point in the history
  • Loading branch information
iskomir committed Apr 6, 2024
1 parent b27852d commit b2618fb
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions auth_lib/fastapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,15 +65,15 @@ def __init__(
)
self.scopes = scopes

def _except_authorization(self):
def _except_not_authorized(self):
if self.auto_error:
raise HTTPException(
status_code=HTTP_401_UNAUTHORIZED, detail="Not authorized"
)
else:
return None

def _except_authentificated(self):
def _except_not_authentificated(self):
if self.auto_error:
raise HTTPException(
status_code=HTTP_403_FORBIDDEN, detail="Not authenticated"
Expand All @@ -85,7 +85,7 @@ async def _get_session(self, token: str | None) -> dict[str, Any] | None:
if not token and self.allow_none:
return None
if not token:
return self._except_authorization()
return self._except_not_authorized()
return await AsyncAuthLib(auth_url=self.auth_url).check_token(token)

async def _get_userdata(
Expand All @@ -94,7 +94,7 @@ async def _get_userdata(
if not token and self.allow_none:
return None
if not token:
return self._except_authorization()
return self._except_not_authorized()
if self.enable_userdata:
return await AsyncAuthLib(userdata_url=self.userdata_url).get_user_data(
token, user_id
Expand All @@ -108,7 +108,7 @@ async def __call__(
token = request.headers.get("Authorization")
result = await self._get_session(token)
if result is None:
return self._except_authorization()
return self._except_not_authorized()
if self.enable_userdata:
user_data_info = await self._get_userdata(token, result["id"])
result["userdata"] = []
Expand All @@ -119,5 +119,5 @@ async def __call__(
)
required_scopes = set([scope.lower() for scope in self.scopes])
if required_scopes - session_scopes:
self._except_authentificated()
self._except_not_authentificated()
return result

0 comments on commit b2618fb

Please sign in to comment.