@@ -49,13 +49,17 @@ app.add_middleware(
4949 allow_headers=["*"],
5050)
5151
52- from cloudharness.middleware import set_authentication_token
52+ from cloudharness.middleware import set_authentication_token, get_authentication_token
5353@app.middleware("http")
5454async def add_process_time_header(request: Request, call_next):
5555 # retrieve the bearer token from the header
5656 # and save it for use in the AuthClient
57- authorization = request.headers.get('Authorization')
57+ authorization = request.headers.get('Authorization') or request.cookies.get('kc-access')
58+
5859 if authorization:
60+ if 'Bearer ' in authorization:
61+ authorization = authorization.split('Bearer ')[1]
62+
5963 set_authentication_token(authorization)
6064
6165 return await call_next(request)
@@ -67,16 +71,17 @@ if os.environ.get('KUBERNETES_SERVICE_HOST', None):
6771 # start the kafka event listener when running in/for k8s
6872 import cloudharness_django.services.events
6973
70- # enable the Bearer Authentication
71- security = HTTPBearer()
72-
73- async def has_access(credentials: HTTPBasicCredentials = Depends(security)):
74+ async def has_access():
7475 """
7576 Function that is used to validate the token in the case that it requires it
7677 """
7778 if not os.environ.get('KUBERNETES_SERVICE_HOST', None):
7879 return {}
79- token = credentials.credentials
80+
81+ token = get_authentication_token()
82+
83+ if not token:
84+ raise HTTPException(status_code=401)
8085
8186 try:
8287 payload = get_auth_service().get_auth_client().decode_token(token)
0 commit comments