🔒️ Add optionally_authenticated permission
This commit is contained in:
parent
1c42b44d41
commit
643a6b2eb7
1 changed files with 7 additions and 1 deletions
|
|
@ -1,6 +1,6 @@
|
||||||
import time
|
import time
|
||||||
from enum import Enum
|
from enum import Enum
|
||||||
from typing import Any, Dict, List
|
from typing import Any, Dict, List, Optional
|
||||||
|
|
||||||
import jwt
|
import jwt
|
||||||
import settings
|
import settings
|
||||||
|
|
@ -124,6 +124,12 @@ async def get_current_user(token: str = Depends(oauth2_scheme)) -> User:
|
||||||
return user
|
return user
|
||||||
|
|
||||||
|
|
||||||
|
async def optionally_authenticated(token: Optional[str] = Depends(oauth2_scheme)) -> Optional[User]:
|
||||||
|
if token is None:
|
||||||
|
return None
|
||||||
|
return await get_current_user(token)
|
||||||
|
|
||||||
|
|
||||||
async def require_authenticated(current_user: User = Depends(get_current_user)) -> User:
|
async def require_authenticated(current_user: User = Depends(get_current_user)) -> User:
|
||||||
"""Ensure the current user is an admin."""
|
"""Ensure the current user is an admin."""
|
||||||
if not current_user:
|
if not current_user:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue