auth and token middleware context update
This commit is contained in:
@@ -15,6 +15,7 @@ from fastapi import Request, Response
|
||||
from starlette.middleware.base import BaseHTTPMiddleware
|
||||
|
||||
from ApiLayers.ApiLibrary.common.line_number import get_line_number_for_error
|
||||
from ApiLayers.ApiValidations.Custom.wrapper_contexts import AuthContext
|
||||
from ApiLayers.ErrorHandlers.ErrorHandlers.api_exc_handler import HTTPExceptionApi
|
||||
from ApiLayers.AllConfigs.Token.config import Auth
|
||||
from ApiLayers.ApiServices.Token.token_handler import TokenService
|
||||
@@ -87,20 +88,25 @@ class MiddlewareModule:
|
||||
@wraps(func)
|
||||
async def wrapper(request: Request, *args, **kwargs):
|
||||
# Get and validate token context from request
|
||||
auth_context = {
|
||||
"is_employee": False,
|
||||
"is_occupant": False,
|
||||
"context": {}
|
||||
}
|
||||
|
||||
endpoint_url = str(request.url.path)
|
||||
auth_context = AuthContext(
|
||||
auth={"token": {"access_token": "", "refresher_token": "", "context": {}}},
|
||||
url=endpoint_url,
|
||||
)
|
||||
|
||||
# Set auth context on the wrapper function itself
|
||||
setattr(wrapper, 'auth', auth_context)
|
||||
|
||||
setattr(func, 'auth_context', auth_context)
|
||||
setattr(wrapper, 'auth_context', auth_context)
|
||||
|
||||
# Call the original endpoint function
|
||||
if inspect.iscoroutinefunction(func):
|
||||
result = await func(request, *args, **kwargs)
|
||||
else:
|
||||
result = func(request, *args, **kwargs)
|
||||
|
||||
# Set auth context on the wrapper function itself
|
||||
setattr(func, 'auth_context', auth_context)
|
||||
setattr(wrapper, 'auth_context', auth_context)
|
||||
|
||||
return result
|
||||
return wrapper
|
||||
|
||||
Reference in New Issue
Block a user