Skip to content

Commit

Permalink
scopes update (#16)
Browse files Browse the repository at this point in the history
  • Loading branch information
grigoriev-semyon committed Mar 13, 2023
1 parent 93258a3 commit f75013f
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 13 deletions.
5 changes: 3 additions & 2 deletions auth_lib/aiomethods.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

from .exceptions import SessionExpired, AuthFailed, IncorrectData, NotFound

# See docs on https://api.test.profcomff.com/?urls.primaryName=auth

class AsyncAuthLib:
url: str
Expand All @@ -28,7 +29,7 @@ async def check_token(self, token: str) -> dict[str, Any]:
response = await session.get(
url=f"{self.url}/me",
headers=headers,
params={"info": ["groups", "indirect_groups", "scopes"]},
params={"info": ["groups", "indirect_groups", "token_scopes", "user_scopes"]},
)
match response.status:
case 200:
Expand All @@ -41,7 +42,7 @@ async def check_token(self, token: str) -> dict[str, Any]:
raise SessionExpired(response=await response.json())

async def logout(self, token: str) -> bool:
headers = {"token": token}
headers = {"Authorization": token}
async with aiohttp.ClientSession() as session:
response = await session.post(url=f"{self.url}/logout", headers=headers)

Expand Down
12 changes: 5 additions & 7 deletions auth_lib/fastapi.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from urllib.parse import urljoin

import aiohttp
from fastapi.exceptions import HTTPException
from fastapi.openapi.models import APIKey, APIKeyIn
Expand All @@ -18,8 +16,8 @@ class UnionAuth(SecurityBase):

def __init__(
self,
auth_url: str,
auto_error=True,
auth_url: str = "https://api.test.profcomff.com/auth",
auto_error = True,
allow_none: bool = False,
scopes: list[str] = [],
) -> None:
Expand Down Expand Up @@ -48,17 +46,17 @@ async def __call__(
return self._except()
async with aiohttp.request(
"GET",
urljoin(self.auth_url, "/me"),
f"{self.auth_url}/me",
headers={"Authorization": token},
params={"info": ["groups", "indirect_groups", "scopes"]},
params={"info": ["groups", "indirect_groups", "token_scopes", "user_scopes"]},
) as r:
status_code = r.status
user_session = await r.json()
if status_code != 200:
self._except()
if len(
set([scope.lower() for scope in self.scopes])
& set([scope["name"].lower() for scope in user_session["scopes"]])
& set([scope["name"].lower() for scope in user_session["session_scopes"]])
) != len(set([scope.lower() for scope in self.scopes])):
self._except()
return user_session
6 changes: 3 additions & 3 deletions auth_lib/methods.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from .exceptions import SessionExpired, AuthFailed, IncorrectData, NotFound


# See docs on https://auth.api.profcomff.com/docs
# See docs on https://api.test.profcomff.com/?urls.primaryName=auth


class AuthLib:
Expand All @@ -28,7 +28,7 @@ def check_token(self, token: str) -> dict[str, Any]:
response = requests.get(
url=f"{self.url}/me",
headers=headers,
params={"info": ["groups", "indirect_groups", "scopes"]},
params={"info": ["groups", "indirect_groups", "token_scopes", "user_session"]},
)
match response.status_code:
case 200:
Expand All @@ -41,7 +41,7 @@ def check_token(self, token: str) -> dict[str, Any]:
raise SessionExpired(response=response.json()["body"])

def logout(self, token: str) -> bool:
headers = {"token": token}
headers = {"Authorization": token}
response = requests.post(url=f"{self.url}/logout", headers=headers)

match response.status_code:
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

setup(
name="auth_lib_profcomff",
version="2023.02.23",
version="2023.03.13",
author="Semyon Grigoriev",
long_description=readme,
long_description_content_type="text/markdown",
Expand Down

0 comments on commit f75013f

Please sign in to comment.