Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Фикс ошибки AuthLib #46

Merged
merged 11 commits into from
Apr 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 14 additions & 6 deletions auth_lib/fastapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,18 @@ def __init__(
)
self.scopes = scopes

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

def _except_not_authentificated(self):
if self.auto_error:
raise HTTPException(
status_code=HTTP_403_FORBIDDEN, detail="Not authentificated"
)
else:
return None
Expand All @@ -77,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()
return self._except_not_authorized()
return await AsyncAuthLib(auth_url=self.auth_url).check_token(token)

async def _get_userdata(
Expand All @@ -86,7 +94,7 @@ async def _get_userdata(
if not token and self.allow_none:
return None
if not token:
return self._except()
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 @@ -100,7 +108,7 @@ async def __call__(
token = request.headers.get("Authorization")
result = await self._get_session(token)
if result is None:
return self._except()
return self._except_not_authorized()
if self.enable_userdata:
user_data_info = await self._get_userdata(token, result["id"])
result["userdata"] = []
Expand All @@ -111,5 +119,5 @@ async def __call__(
)
required_scopes = set([scope.lower() for scope in self.scopes])
if required_scopes - session_scopes:
self._except()
self._except_not_authentificated()
return result
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

setup(
name="auth_lib_profcomff",
version="2024.04.06",
version="2024.04.07",
author="Semyon Grigoriev",
long_description=readme,
long_description_content_type="text/markdown",
Expand Down
Loading