Initial commit
This commit is contained in:
@@ -0,0 +1,17 @@
|
||||
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(),
|
||||
)
|
||||
Reference in New Issue
Block a user