18 lines
531 B
Python
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(),
|
|
)
|