Chainlit / chainlit

Build Conversational AI in minutes ⚡️
https://docs.chainlit.io
Apache License 2.0
6.1k stars 777 forks source link

Unable to utilize OAuth authentication with custom react frontend due to internal URL #911

Open mikkelgthang opened 2 months ago

mikkelgthang commented 2 months ago

When using @cl.oauth_callback as described in the docs, CHAINLIT_URL can be set to define the backend's URL - which works as expected. However, the RedirectResponse defined in oauth_callback simply calls url=f"/login?{params}", which means that the callback url wrongly uses the CHAINLIT_URL, and not the frontend's URL that made the request. I can see that it includes a FIXME comment, but in case other matters are more pressing, is there potentially any way to overwrite the implementation? I tried to define the same endpoint in my app.py file, but it still uses the internal function. Currently, I have no way of returning the token to my custom frontend url detached from CHAINLIT_URL. 😃

Thank you in advance 👏

brii7 commented 1 month ago

I have the same issue, was any solution found? Not deploying Chainlit's UI would work, only if the react custom frontend is deployed in the same port (8000). But as per Willy's comment on issue 705, Chainlit's UI is always declared last and it cannot be overwritten.

mikkelgthang commented 3 weeks ago

@brii7 Unfortunately, there still seems to be no natively working solution available. For this reason, we opted for a manual "hacky" solution, where we post-package-install in our docker image simply replaces the chainlit/backend/chainlit /server.py file with a modified duplicate, replacing url=f"/login/callback?{params}" with our custom environment url's.

brii7 commented 3 weeks ago

Thank you for your reply and solution. I've also just found out that changing the _custombuild paremeter on the config.toml file, enables you to use your own custom UI folder. But it needs to have a specific structure, which is also not 100% convenient.

mikkelgthang commented 1 week ago

@brii7 it seems they have fixed this issue in their latest versioning 😄

mikkelgthang commented 1 week ago

I was a bit too fast on the trigger, they merely added support for the CHAINLIT_ROOT_PATH, which is a path appended to the base CHAINLIT_URL, not directly transferrable to custom frontend URL. With their new mounted setup however, perhaps a better solution exists using fastapi overwrite.