Skip to content
This repository has been archived by the owner on Jan 7, 2025. It is now read-only.

Commit

Permalink
Slightly improve access grants
Browse files Browse the repository at this point in the history
  • Loading branch information
davenquinn committed Oct 23, 2024
1 parent ea50536 commit 94182c0
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions api/routes/security.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,10 +189,6 @@ async def get_groups(

async def has_access(groups: list[int] = Depends(get_groups)) -> bool:
"""Check if the user has access to the group"""

if "ENVIRONMENT" in os.environ and os.environ["ENVIRONMENT"] == "development":
return True

return 1 in groups


Expand All @@ -211,6 +207,11 @@ def create_access_token(data: dict, expires_delta: timedelta | None = None):
return encoded_jwt


def get_domain(url: str):
parsed_url = urllib.parse.urlparse(url)
return parsed_url.netloc


@router.get("/login")
async def redirect_authorization(return_url: str = None):
"""Redirect to the authorization URL with the appropriate parameters"""
Expand Down Expand Up @@ -354,11 +355,10 @@ async def create_group_token(
async def logout(response: Response):
"""Logout the active user"""

try:
response.delete_cookie(key=access_token_key)
except KeyError:
return {"status": "error", "message": "User is not logged in"}

main_domain = get_domain(os.environ["REDIRECT_URI"])
# Delete all instances of cookies that we might conceivably have set
for domain in [main_domain, "localhost", "127.0.0.1", None]:
response.delete_cookie(key=access_token_key, domain=domain)
return {"status": "success"}


Expand Down

0 comments on commit 94182c0

Please sign in to comment.