Files
2024-02-15 00:17:51 +03:30

18 lines
531 B
Python

from fastapi import Depends
from starlette.authentication import AuthenticationBackend, AuthCredentials
from starlette.middleware.authentication import AuthenticationMiddleware
from core.utils.auth import get_current_user
class OAuth2Backend(AuthenticationBackend):
async def authenticate(self, request, user=Depends(get_current_user)):
return AuthCredentials(["authenticated"]), user
def setup_auth_middleware(app):
app.add_middleware(
AuthenticationMiddleware,
backend=OAuth2Backend(),
)