fix: add custom openauth schema

This commit is contained in:
Boris Arzentar 2025-06-30 15:09:13 +02:00
parent 72ac4bce43
commit 64edb38c43
No known key found for this signature in database
GPG key ID: D5CC274C784807B7
3 changed files with 8 additions and 19 deletions

View file

@ -88,28 +88,24 @@ def custom_openapi():
)
openapi_schema["components"]["securitySchemes"] = {
"BearerAuth": {
"type": "http",
"scheme": "bearer"
},
"BearerAuth": {"type": "http", "scheme": "bearer"},
"CookieAuth": {
"type": "apiKey",
"in": "cookie",
"name": os.getenv("AUTH_TOKEN_COOKIE_NAME", "auth_token")
}
"name": os.getenv("AUTH_TOKEN_COOKIE_NAME", "auth_token"),
},
}
openapi_schema["security"] = [
{"BearerAuth": []},
{"CookieAuth": []}
]
openapi_schema["security"] = [{"BearerAuth": []}, {"CookieAuth": []}]
app.openapi_schema = openapi_schema
return app.openapi_schema
app.openapi = custom_openapi
@app.exception_handler(RequestValidationError)
async def request_validation_exception_handler(request: Request, exc: RequestValidationError):
if request.url.path == "/api/v1/auth/login":

View file

@ -56,6 +56,7 @@ class UserManager(UUIDIDMixin, BaseUserManager[User, uuid.UUID]):
response.body = json.dumps(
{"access_token": access_token, "token_type": "bearer"}
).encode(encoding="utf-8")
response.headers.append("Content-Type", "application/json")
async def on_after_register(self, user: User, request: Optional[Request] = None):
print(f"User {user.id} has registered.")

View file

@ -1,17 +1,9 @@
from cognee.modules.users.authentication.get_api_auth_backend import get_api_auth_backend
from cognee.modules.users.authentication.get_client_auth_backend import get_client_auth_backend
from ..get_fastapi_users import get_fastapi_users
fastapi_users = get_fastapi_users()
def get_enabled_backends():
api_auth_backend = get_api_auth_backend()
client_auth_backend = get_client_auth_backend()
return [api_auth_backend, client_auth_backend]
get_authenticated_user = fastapi_users.current_user(active=True, get_enabled_backends=get_enabled_backends)
get_authenticated_user = fastapi_users.current_user(active=True)
# from types import SimpleNamespace