Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable auth using trusted header #1128

Merged
merged 9 commits into from
May 29, 2024
Merged

Conversation

lijunle
Copy link
Contributor

@lijunle lijunle commented May 10, 2024

I am hosting Chat-UI after Cloudflare Tunnel and using Cloudflare Access for SSO.

After SSO, Cloudflare will inject a cookie CF_Authorization. Its value is a JWT. We could use the email after decoding the JWT value as login user.

Nathan edit: We updated the PR to use a header instead of a cookie to get the logged in user. See this for more info.

@nsarrazin
Copy link
Collaborator

nsarrazin commented May 23, 2024

Hi! Thanks for the contribution, big fan of cloudflare tunnels 😁

I pushed a commit to fix the user creation and make sure everything passes the tests. I'm worried that because you override the id, all users will share the same conversations. I think we should use the user email decoded from the JWT to generate a user id.

Then you'd need to find another way to hide the sign-out button. Maybe check if the cookie is set in the front-end instead ?

@lijunle
Copy link
Contributor Author

lijunle commented May 23, 2024

@nsarrazin I am looking at Open-WebUI and they are using HTTP header instead of cookie to retrieve the user email. It looks like that is flexible to be compatible with Cloudflare Tunnel, Tailscale, OAuth0 and other SSO. Do you think that is a better option?

https://docs.openwebui.com/tutorial/sso#cloudflare-tunnel-with-cloudflare-access

@nsarrazin
Copy link
Collaborator

I updated the implementation to use the header instead of the cookie. I also fixed the issue I mentioned above. Didn't yet try it as i'm travelling, will try it with cloudflare locally when I can but if you could give it a spin and let me know if it works for you as well, would be great!

@nsarrazin nsarrazin changed the title Use JWT email as login user Enable auth using trusted header May 24, 2024
@nsarrazin nsarrazin added enhancement New feature or request back This issue is related to the Svelte backend or the DB labels May 27, 2024
@nsarrazin
Copy link
Collaborator

Feel free to take a quick look at the PR if you have the time, we won't be using it for huggingchat but because this touches the login code i'd like to get some other pairs of eyes on the PR 🤗

Copy link
Member

@coyotte508 coyotte508 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice to see a small diff like this for a feature add :)

My only question is do we need to set hfUserId: email but looks good

@nsarrazin nsarrazin merged commit 6ff704b into huggingface:main May 29, 2024
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
back This issue is related to the Svelte backend or the DB enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants