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

Libs 27 move authz to checker #9

Merged
merged 3 commits into from
Jul 15, 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
4 changes: 3 additions & 1 deletion auth_checker/models/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@ def __init__(
class TokenAuthorizer:
def __init__(self, roles: list[str]):
self.authorized_roles = roles
self.token = None

def __call__(self, token: Annotated[TokenValidator, Depends(TokenValidator)]):
if not token.account:
Expand All @@ -215,7 +216,8 @@ def __call__(self, token: Annotated[TokenValidator, Depends(TokenValidator)]):
raise HTTPException(401, detail="User has no roles")
if not any(role in self.authorized_roles for role in token.account.roles):
raise HTTPException(403, detail="User is not authorized to perform this action")
return True
self.token = token.token
return self


def _encode_jwt(payload: dict, secret: str, algorithm: str) -> str:
Expand Down
Loading
Loading