Not able to report new incident (/incident/report) with basic auth
Describe the bug Issue with basic authentication
To Reproduce Steps to reproduce the behavior:
- Install dispatch with basic authentication - dispatch-auth-provider-basic
- When you go to dispatch URL, we are not being redirected to register/login endpoint. (This needs to be looked at).
- After manually going to /register endpoint and registering yourself, you will be directed to dashboards pane. - This works as expected.
- Now, refreshing the same screen (F5), you will get below error.
ERROR:uvicorn.error:Exception in ASGI application
Traceback (most recent call last):
File "/usr/local/lib/python3.8/site-packages/uvicorn/protocols/http/httptools_impl.py", line 390, in run_asgi
result = await app(self.scope, self.receive, self.send)
File "/usr/local/lib/python3.8/site-packages/uvicorn/middleware/proxy_headers.py", line 45, in __call__
return await self.app(scope, receive, send)
File "/usr/local/lib/python3.8/site-packages/starlette/applications.py", line 111, in __call__
await self.middleware_stack(scope, receive, send)
File "/usr/local/lib/python3.8/site-packages/starlette/middleware/errors.py", line 181, in __call__
raise exc from None
File "/usr/local/lib/python3.8/site-packages/starlette/middleware/errors.py", line 159, in __call__
await self.app(scope, receive, _send)
File "/usr/local/lib/python3.8/site-packages/starlette/middleware/base.py", line 26, in __call__
await response(scope, receive, send)
File "/usr/local/lib/python3.8/site-packages/starlette/responses.py", line 228, in __call__
await run_until_first_complete(
File "/usr/local/lib/python3.8/site-packages/starlette/concurrency.py", line 18, in run_until_first_complete
[task.result() for task in done]
File "/usr/local/lib/python3.8/site-packages/starlette/concurrency.py", line 18, in <listcomp>
[task.result() for task in done]
File "/usr/local/lib/python3.8/site-packages/starlette/responses.py", line 220, in stream_response
async for chunk in self.body_iterator:
File "/usr/local/lib/python3.8/site-packages/starlette/middleware/base.py", line 56, in body_stream
task.result()
File "/usr/local/lib/python3.8/site-packages/starlette/middleware/base.py", line 38, in coro
await self.app(scope, receive, send)
File "/usr/local/lib/python3.8/site-packages/sentry_asgi/middleware.py", line 22, in __call__
raise exc from None
File "/usr/local/lib/python3.8/site-packages/sentry_asgi/middleware.py", line 19, in __call__
await self.app(scope, receive, send)
File "/usr/local/lib/python3.8/site-packages/starlette/middleware/base.py", line 26, in __call__
await response(scope, receive, send)
File "/usr/local/lib/python3.8/site-packages/starlette/responses.py", line 228, in __call__
await run_until_first_complete(
File "/usr/local/lib/python3.8/site-packages/starlette/concurrency.py", line 18, in run_until_first_complete
[task.result() for task in done]
File "/usr/local/lib/python3.8/site-packages/starlette/concurrency.py", line 18, in <listcomp>
[task.result() for task in done]
File "/usr/local/lib/python3.8/site-packages/starlette/responses.py", line 220, in stream_response
async for chunk in self.body_iterator:
File "/usr/local/lib/python3.8/site-packages/starlette/middleware/base.py", line 56, in body_stream
task.result()
File "/usr/local/lib/python3.8/site-packages/starlette/middleware/base.py", line 38, in coro
await self.app(scope, receive, send)
File "/usr/local/lib/python3.8/site-packages/starlette/middleware/base.py", line 26, in __call__
await response(scope, receive, send)
File "/usr/local/lib/python3.8/site-packages/starlette/responses.py", line 228, in __call__
await run_until_first_complete(
File "/usr/local/lib/python3.8/site-packages/starlette/concurrency.py", line 18, in run_until_first_complete
[task.result() for task in done]
File "/usr/local/lib/python3.8/site-packages/starlette/concurrency.py", line 18, in <listcomp>
[task.result() for task in done]
File "/usr/local/lib/python3.8/site-packages/starlette/responses.py", line 220, in stream_response
async for chunk in self.body_iterator:
File "/usr/local/lib/python3.8/site-packages/starlette/middleware/base.py", line 56, in body_stream
task.result()
File "/usr/local/lib/python3.8/site-packages/starlette/middleware/base.py", line 38, in coro
await self.app(scope, receive, send)
File "/usr/local/lib/python3.8/site-packages/starlette/exceptions.py", line 82, in __call__
raise exc from None
File "/usr/local/lib/python3.8/site-packages/starlette/exceptions.py", line 71, in __call__
await self.app(scope, receive, sender)
File "/usr/local/lib/python3.8/site-packages/starlette/routing.py", line 566, in __call__
await route.handle(scope, receive, send)
File "/usr/local/lib/python3.8/site-packages/starlette/routing.py", line 376, in handle
await self.app(scope, receive, send)
File "/usr/local/lib/python3.8/site-packages/fastapi/applications.py", line 179, in __call__
await super().__call__(scope, receive, send)
File "/usr/local/lib/python3.8/site-packages/starlette/applications.py", line 111, in __call__
await self.middleware_stack(scope, receive, send)
File "/usr/local/lib/python3.8/site-packages/starlette/middleware/errors.py", line 181, in __call__
raise exc from None
File "/usr/local/lib/python3.8/site-packages/starlette/middleware/errors.py", line 159, in __call__
await self.app(scope, receive, _send)
File "/usr/local/lib/python3.8/site-packages/starlette/exceptions.py", line 82, in __call__
raise exc from None
File "/usr/local/lib/python3.8/site-packages/starlette/exceptions.py", line 71, in __call__
await self.app(scope, receive, sender)
File "/usr/local/lib/python3.8/site-packages/starlette/routing.py", line 566, in __call__
await route.handle(scope, receive, send)
File "/usr/local/lib/python3.8/site-packages/starlette/routing.py", line 227, in handle
await self.app(scope, receive, send)
File "/usr/local/lib/python3.8/site-packages/starlette/routing.py", line 41, in app
response = await func(request)
File "/usr/local/lib/python3.8/site-packages/fastapi/routing.py", line 172, in app
solved_result = await solve_dependencies(
File "/usr/local/lib/python3.8/site-packages/fastapi/dependencies/utils.py", line 552, in solve_dependencies
solved = await run_in_threadpool(call, **sub_values)
File "/usr/local/lib/python3.8/site-packages/starlette/concurrency.py", line 34, in run_in_threadpool
return await loop.run_in_executor(None, func, *args)
File "/usr/local/lib/python3.8/concurrent/futures/thread.py", line 57, in run
result = self.fn(*self.args, **self.kwargs)
File "/usr/local/lib/python3.8/site-packages/dispatch/auth/service.py", line 82, in get_current_user
return get_or_create(db_session=db_session, user_in=UserRegister(email=user_email))
File "pydantic/main.py", line 346, in pydantic.main.BaseModel.__init__
pydantic.error_wrappers.ValidationError: 1 validation error for UserRegister
email
none is not an allowed value (type=type_error.none.not_allowed)
Inspecting using Chrome Dev tool shows Bearer token is missing when screen is refreshed or going to other endpoints like /incident/report.
Expected behavior Expect the Bearer token gets passed through for all subsequent calls.
Screenshots
If applicable, add screenshots to help explain your problem.

@santhoshparepu thanks for the detailed report. I just ran through your steps on the latest master branch and wasn't able to reproduce, specifically:
- When I was unauthenticated I was redirected to /login
- Upon registering I was redirected to the dashboard
- I was able to navigate to other pages as well
- I was still able to use the app have a refresh
Some more questions:
- Which browser are you using?
- Is this running locally or deployed behind an ELB/Proxy?
- Is there any other interesting console errors or request header you might be able to provide?
@kevgliss Here is the .env file I am using. Just to confirm, I am cloning dispatch-docker, modifying .env file and running ./install.sh.
COMPOSE_PROJECT_NAME=dispatch
[email protected]
DISPATCH_HELP_SLACK_CHANNEL=#general
DISPATCH_UI_URL=https://xxx.yyyy.xxx
DISPATCH_AUTHENTICATION_PROVIDER_SLUG=dispatch-auth-provider-basic
SECRET_KEY="xxxxx"
DISPATCH_JWT_SECRET="xxx"
.
.
.
- Which browser are you using? I am seeing this in Safari, Chrome and Firefox.
- Is this running locally or deployed behind an ELB/Proxy? It is running on ubuntu VM and I am accessing this from my laptop.
- Is there any other interesting console errors or request header you might be able to provide? The error I posted in the only interesting thing I see the console logs. Screenshot posted above contains request headers. As I mentioned Authorization header is the only missing piece between successful and unsuccessful attempts.
@kevgliss Please let me know if you need more information from me.
Okay, I think I might understand what is happening... talking this through.
It seems that you are running the VM behind a DNS name, e.g. DISPATCH_UI_URL=https://xxx.yyyy.xxx for testing purposes I would access it directly via localhost and see if that resolves the issue. I believe that the frontend code is attempting to make a cross-origin request although we don't allow it (the server doesn't include a header to allow these types of requests).
We don't typically see this in production because we have a load balancer in front of our application, what we probably need to do to enable you to set your own hostname without a proxy is to define a DISPATCH_HOSTNAME that can be used by DISPATCH_UI_URL and be included in a CORS request header sent by the server.
If accessing via localhost works, I will put together a PR for the CORS changes.
`
@kevgliss I switched to pkce and got page redirected to our Auth provider. Now, we are facing CORS issue. Isn't DISPATCH_UI_URL used for notifications only? Is this used as hostname too. And you mentioned about load balancer front-ending application servers. How do you ensure the notifications contains correct URL by setting DISPATH_UI_URL to localhost?
Access to fetch at 'xxx.com/..../token' from origin 'https://yyy.com' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.
I don't think pkce vs basic-auth is the issue here, it's a CORS issue, essentially you are attempting to access the app from a domain https://yyy.com that loads our app/js. Once loaded, the app attempts to fetch resources from the Dispatch API (auth data in this case), which looks like it's on a different domain than the app itself.
There are two options:
- Host the frontend and the API on the same domain (this is what we do in the load balancer case)
- Have the server allow the second domain via an
Access-Control-Allow-Originheader
You're correct DISPATH_UI_URL is only used for notification. To test my theory, I don't think you should modify this value. Instead, simply access the dispatch app via http://localhost:8000/dashboard or whatever makes sense and ensure that both the frontend and backend are using the same server.
I believe this should be the default when using the docker image (accessing the web service by it's docker IP).