From e1d54abf523b239d299fbfea9844eb41e9f89910 Mon Sep 17 00:00:00 2001 From: iskomir <151797312+iskomir@users.noreply.github.com> Date: Sun, 7 Apr 2024 00:51:08 +0300 Subject: [PATCH 01/14] Update fastapi.py --- auth_lib/fastapi.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/auth_lib/fastapi.py b/auth_lib/fastapi.py index 7555840..fa422f2 100644 --- a/auth_lib/fastapi.py +++ b/auth_lib/fastapi.py @@ -68,7 +68,7 @@ def __init__( def _except(self): if self.auto_error: raise HTTPException( - status_code=HTTP_403_FORBIDDEN, detail="Not authenticated" + status_code=HTTP_403_FORBIDDEN, detail="Not authorized" ) else: return None From a0d5af88d6f0b4558e229d66c0200b858c095441 Mon Sep 17 00:00:00 2001 From: iskomir Date: Sun, 7 Apr 2024 00:55:13 +0300 Subject: [PATCH 02/14] Update fastapi.py --- auth_lib/fastapi.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/auth_lib/fastapi.py b/auth_lib/fastapi.py index fa422f2..f336d9a 100644 --- a/auth_lib/fastapi.py +++ b/auth_lib/fastapi.py @@ -67,9 +67,7 @@ def __init__( def _except(self): if self.auto_error: - raise HTTPException( - status_code=HTTP_403_FORBIDDEN, detail="Not authorized" - ) + raise HTTPException(status_code=HTTP_403_FORBIDDEN, detail="Not authorized") else: return None From 562b0844a92a8646a92c6ca83ded63ae01a979c5 Mon Sep 17 00:00:00 2001 From: iskomir Date: Sun, 7 Apr 2024 01:47:24 +0300 Subject: [PATCH 03/14] Update fastapi.py --- auth_lib/fastapi.py | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/auth_lib/fastapi.py b/auth_lib/fastapi.py index f336d9a..eb9856f 100644 --- a/auth_lib/fastapi.py +++ b/auth_lib/fastapi.py @@ -65,17 +65,23 @@ def __init__( ) self.scopes = scopes - def _except(self): + def _except_authentification(self): + if self.auto_error: + raise HTTPException(status_code=HTTP_401_UNAUTHORIZED, detail="Not authenticated") + else: + return None + + def _except_authorization(self): if self.auto_error: raise HTTPException(status_code=HTTP_403_FORBIDDEN, detail="Not authorized") else: return None - + 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_authentification() return await AsyncAuthLib(auth_url=self.auth_url).check_token(token) async def _get_userdata( @@ -84,7 +90,7 @@ async def _get_userdata( if not token and self.allow_none: return None if not token: - return self._except() + return self._except_authentification() if self.enable_userdata: return await AsyncAuthLib(userdata_url=self.userdata_url).get_user_data( token, user_id @@ -98,7 +104,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_authentification() if self.enable_userdata: user_data_info = await self._get_userdata(token, result["id"]) result["userdata"] = [] @@ -109,5 +115,5 @@ async def __call__( ) required_scopes = set([scope.lower() for scope in self.scopes]) if required_scopes - session_scopes: - self._except() + self._except_authorization() return result From 36bf51bcb01b2ff005185d334c082bcee286a26f Mon Sep 17 00:00:00 2001 From: iskomir Date: Sun, 7 Apr 2024 01:52:50 +0300 Subject: [PATCH 04/14] Update fastapi.py --- auth_lib/fastapi.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/auth_lib/fastapi.py b/auth_lib/fastapi.py index eb9856f..b8bf581 100644 --- a/auth_lib/fastapi.py +++ b/auth_lib/fastapi.py @@ -67,16 +67,18 @@ def __init__( def _except_authentification(self): if self.auto_error: - raise HTTPException(status_code=HTTP_401_UNAUTHORIZED, detail="Not authenticated") + raise HTTPException( + status_code=HTTP_401_UNAUTHORIZED, detail="Not authenticated" + ) else: return None - + def _except_authorization(self): if self.auto_error: raise HTTPException(status_code=HTTP_403_FORBIDDEN, detail="Not authorized") else: return None - + async def _get_session(self, token: str | None) -> dict[str, Any] | None: if not token and self.allow_none: return None From 4fc4889556e814d3ea3959e9dd9ab36a53c8ef3b Mon Sep 17 00:00:00 2001 From: iskomir Date: Sun, 7 Apr 2024 01:56:09 +0300 Subject: [PATCH 05/14] Update fastapi.py --- auth_lib/fastapi.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/auth_lib/fastapi.py b/auth_lib/fastapi.py index b8bf581..1e74ec2 100644 --- a/auth_lib/fastapi.py +++ b/auth_lib/fastapi.py @@ -68,14 +68,16 @@ def __init__( def _except_authentification(self): if self.auto_error: raise HTTPException( - status_code=HTTP_401_UNAUTHORIZED, detail="Not authenticated" + status_code=HTTP_401_UNAUTHORIZED, detail="Not authorized" ) else: return None def _except_authorization(self): if self.auto_error: - raise HTTPException(status_code=HTTP_403_FORBIDDEN, detail="Not authorized") + raise HTTPException( + status_code=HTTP_403_FORBIDDEN, detail="Not authenticated" + ) else: return None From e4f4c847af4463ed92658da6869d9df114489811 Mon Sep 17 00:00:00 2001 From: iskomir Date: Sun, 7 Apr 2024 02:13:01 +0300 Subject: [PATCH 06/14] Update fastapi.py --- auth_lib/fastapi.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/auth_lib/fastapi.py b/auth_lib/fastapi.py index 1e74ec2..cb4ecf1 100644 --- a/auth_lib/fastapi.py +++ b/auth_lib/fastapi.py @@ -65,7 +65,7 @@ def __init__( ) self.scopes = scopes - def _except_authentification(self): + def _except_authorization(self): if self.auto_error: raise HTTPException( status_code=HTTP_401_UNAUTHORIZED, detail="Not authorized" @@ -73,7 +73,7 @@ def _except_authentification(self): else: return None - def _except_authorization(self): + def _except_authentification(self): if self.auto_error: raise HTTPException( status_code=HTTP_403_FORBIDDEN, detail="Not authenticated" From 6e30bae2826e9978ba7bc35da5bfd19434515728 Mon Sep 17 00:00:00 2001 From: iskomir Date: Sun, 7 Apr 2024 02:20:53 +0300 Subject: [PATCH 07/14] Update fastapi.py --- auth_lib/fastapi.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/auth_lib/fastapi.py b/auth_lib/fastapi.py index cb4ecf1..abb6e38 100644 --- a/auth_lib/fastapi.py +++ b/auth_lib/fastapi.py @@ -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_authentification() + return self._except_authorization() return await AsyncAuthLib(auth_url=self.auth_url).check_token(token) async def _get_userdata( @@ -94,7 +94,7 @@ async def _get_userdata( if not token and self.allow_none: return None if not token: - return self._except_authentification() + return self._except_authorization() if self.enable_userdata: return await AsyncAuthLib(userdata_url=self.userdata_url).get_user_data( token, user_id @@ -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_authentification() + return self._except_authorization() if self.enable_userdata: user_data_info = await self._get_userdata(token, result["id"]) result["userdata"] = [] @@ -119,5 +119,5 @@ async def __call__( ) required_scopes = set([scope.lower() for scope in self.scopes]) if required_scopes - session_scopes: - self._except_authorization() + self._except_authentification() return result From 97085fdb4db0212a2caa295cb97d44fce0d007c2 Mon Sep 17 00:00:00 2001 From: iskomir Date: Sun, 7 Apr 2024 02:35:58 +0300 Subject: [PATCH 08/14] Update fastapi.py --- auth_lib/fastapi.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/auth_lib/fastapi.py b/auth_lib/fastapi.py index abb6e38..d14affa 100644 --- a/auth_lib/fastapi.py +++ b/auth_lib/fastapi.py @@ -73,7 +73,7 @@ def _except_authorization(self): else: return None - def _except_authentification(self): + def _except_authentificated(self): if self.auto_error: raise HTTPException( status_code=HTTP_403_FORBIDDEN, detail="Not authenticated" @@ -119,5 +119,5 @@ async def __call__( ) required_scopes = set([scope.lower() for scope in self.scopes]) if required_scopes - session_scopes: - self._except_authentification() + self._except_authentificated() return result From b27852ddb2effaa0ae8cc2bc98e71b210de22359 Mon Sep 17 00:00:00 2001 From: iskomir Date: Sun, 7 Apr 2024 02:38:45 +0300 Subject: [PATCH 09/14] Update setup.py --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index e60b586..0d5d9d2 100644 --- a/setup.py +++ b/setup.py @@ -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", From b2618fbc7b675f653e16557eaa2aa658208d2b68 Mon Sep 17 00:00:00 2001 From: iskomir Date: Sun, 7 Apr 2024 02:44:36 +0300 Subject: [PATCH 10/14] Update fastapi.py --- auth_lib/fastapi.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/auth_lib/fastapi.py b/auth_lib/fastapi.py index d14affa..23b920d 100644 --- a/auth_lib/fastapi.py +++ b/auth_lib/fastapi.py @@ -65,7 +65,7 @@ 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" @@ -73,7 +73,7 @@ def _except_authorization(self): 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" @@ -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( @@ -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 @@ -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"] = [] @@ -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 From f4fc5d62ee5f8b6e26d3e4c7c07865f92591e03f Mon Sep 17 00:00:00 2001 From: iskomir Date: Sun, 7 Apr 2024 02:59:48 +0300 Subject: [PATCH 11/14] Update fastapi.py --- auth_lib/fastapi.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/auth_lib/fastapi.py b/auth_lib/fastapi.py index 23b920d..e6481ba 100644 --- a/auth_lib/fastapi.py +++ b/auth_lib/fastapi.py @@ -76,7 +76,7 @@ def _except_not_authorized(self): def _except_not_authentificated(self): if self.auto_error: raise HTTPException( - status_code=HTTP_403_FORBIDDEN, detail="Not authenticated" + status_code=HTTP_403_FORBIDDEN, detail="Not authentificated" ) else: return None From b8a5da00ba79c8fa8ae64cfcd40bedeba6d4cf05 Mon Sep 17 00:00:00 2001 From: iskomir <151797312+iskomir@users.noreply.github.com> Date: Sun, 7 Apr 2024 03:16:03 +0300 Subject: [PATCH 12/14] =?UTF-8?q?=D0=98=D0=BC=D0=BF=D0=BE=D1=80=D1=82?= =?UTF-8?q?=D0=B8=D1=80=D0=BE=D0=B2=D0=B0=D0=BD=D0=B8=D0=B5=20=D0=BE=D1=88?= =?UTF-8?q?=D0=B8=D0=B1=D0=BA=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- auth_lib/fastapi.py | 1 + 1 file changed, 1 insertion(+) diff --git a/auth_lib/fastapi.py b/auth_lib/fastapi.py index e6481ba..0f2c650 100644 --- a/auth_lib/fastapi.py +++ b/auth_lib/fastapi.py @@ -8,6 +8,7 @@ from pydantic_settings import BaseSettings from starlette.requests import Request from starlette.status import HTTP_403_FORBIDDEN +from starlette.status import HTTP_401_UNAUTHORIZED from auth_lib.aiomethods import AsyncAuthLib From 8506a3be0dc452932a3f4d525760504e69ea66b2 Mon Sep 17 00:00:00 2001 From: iskomir Date: Sun, 7 Apr 2024 03:20:21 +0300 Subject: [PATCH 13/14] Update fastapi.py --- auth_lib/fastapi.py | 1 - 1 file changed, 1 deletion(-) diff --git a/auth_lib/fastapi.py b/auth_lib/fastapi.py index 0f2c650..8d12cba 100644 --- a/auth_lib/fastapi.py +++ b/auth_lib/fastapi.py @@ -9,7 +9,6 @@ from starlette.requests import Request from starlette.status import HTTP_403_FORBIDDEN from starlette.status import HTTP_401_UNAUTHORIZED - from auth_lib.aiomethods import AsyncAuthLib From 9316e985e7c392ed5f68512e16c8b300e53d57e4 Mon Sep 17 00:00:00 2001 From: iskomir Date: Sun, 7 Apr 2024 03:21:34 +0300 Subject: [PATCH 14/14] Update fastapi.py --- auth_lib/fastapi.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/auth_lib/fastapi.py b/auth_lib/fastapi.py index 8d12cba..c59eb89 100644 --- a/auth_lib/fastapi.py +++ b/auth_lib/fastapi.py @@ -7,8 +7,8 @@ from pydantic import ConfigDict from pydantic_settings import BaseSettings from starlette.requests import Request -from starlette.status import HTTP_403_FORBIDDEN -from starlette.status import HTTP_401_UNAUTHORIZED +from starlette.status import HTTP_401_UNAUTHORIZED, HTTP_403_FORBIDDEN + from auth_lib.aiomethods import AsyncAuthLib