diff --git a/application-templates/django-app/api/templates/main.jinja2 b/application-templates/django-app/api/templates/main.jinja2 index d3177fd78..e351e841f 100644 --- a/application-templates/django-app/api/templates/main.jinja2 +++ b/application-templates/django-app/api/templates/main.jinja2 @@ -49,13 +49,17 @@ app.add_middleware( allow_headers=["*"], ) -from cloudharness.middleware import set_authentication_token +from cloudharness.middleware import set_authentication_token, get_authentication_token @app.middleware("http") async def add_process_time_header(request: Request, call_next): # retrieve the bearer token from the header # and save it for use in the AuthClient - authorization = request.headers.get('Authorization') + authorization = request.headers.get('Authorization') or request.cookies.get('kc-access') + if authorization: + if 'Bearer ' in authorization: + authorization = authorization.split('Bearer ')[1] + set_authentication_token(authorization) return await call_next(request) @@ -67,16 +71,17 @@ if os.environ.get('KUBERNETES_SERVICE_HOST', None): # start the kafka event listener when running in/for k8s import cloudharness_django.services.events -# enable the Bearer Authentication -security = HTTPBearer() - -async def has_access(credentials: HTTPBasicCredentials = Depends(security)): +async def has_access(): """ Function that is used to validate the token in the case that it requires it """ if not os.environ.get('KUBERNETES_SERVICE_HOST', None): return {} - token = credentials.credentials + + token = get_authentication_token() + + if not token: + raise HTTPException(status_code=401) try: payload = get_auth_service().get_auth_client().decode_token(token) diff --git a/application-templates/webapp/frontend/src/App.tsx b/application-templates/webapp/frontend/src/App.tsx index 5f2286b29..7e620ca73 100644 --- a/application-templates/webapp/frontend/src/App.tsx +++ b/application-templates/webapp/frontend/src/App.tsx @@ -3,14 +3,14 @@ import Version from './components/Version'; const Main = () => ( - <> - -

__APP_NAME__ React application is working!

- - -

See api documentation here

- - ) + <> + +

__APP_NAME__ React application is working!

+ + +

See api documentation here

+ +) export default Main; diff --git a/application-templates/webapp/frontend/vite.config.ts b/application-templates/webapp/frontend/vite.config.ts index 15155d738..1d1df3944 100644 --- a/application-templates/webapp/frontend/vite.config.ts +++ b/application-templates/webapp/frontend/vite.config.ts @@ -10,7 +10,7 @@ export default defineConfig(({ mode }) => { const env = loadEnv(mode, process.cwd(), '') const theDomain = env && env.DOMAIN ? env.DOMAIN : 'localhost:5000'; - + console.log('Dev server address: ', theDomain); const proxyTarget = theDomain; @@ -22,21 +22,23 @@ export default defineConfig(({ mode }) => { return { - plugins: [react()], - server: { - port: 9000, - proxy: { - '/api/': { - target: replaceHost( proxyTarget, 'samples'), - secure: false, - changeOrigin: true, - }, - '/proxy/common/api': { - target: replaceHost( proxyTarget, 'common'), - secure: false, - changeOrigin: true, - rewrite: (path) => path.replace(/^\/proxy\/common\/api/, '/api') + plugins: [react()], + server: { + port: 9000, + proxy: { + '/api/': { + target: replaceHost(proxyTarget, 'samples'), + secure: false, + changeOrigin: true, + }, + '/proxy/common/api': { + target: replaceHost(proxyTarget, 'common'), + secure: false, + changeOrigin: true, + rewrite: (path) => path.replace(/^\/proxy\/common\/api/, '/api') + } } + } } -}}} +} )