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

Allow external authentication? #489

Closed
dcode opened this issue Jan 31, 2020 · 15 comments
Closed

Allow external authentication? #489

dcode opened this issue Jan 31, 2020 · 15 comments
Assignees
Labels
area: auth extra: help wanted Extra attention is needed type: discussion General talk without any clear action

Comments

@dcode
Copy link

dcode commented Jan 31, 2020

I've been looking around for a Reddit-like option for a self-hosted application. Lemmy looks like a great opportunity for what I need, especially with the RSS feeds.

That said, I need to be able to authenticate to an external resource so I can use the reverse proxy sitting in front of Lemmy to completely restrict access to the site until a user has authenticated with our SSO platform (could be JWT, OpenID, SAML, Basic Auth, whatev).

I think there's a couple of ways to implement this, but I'm not (yet) a Rust developer or I'd hack it in and do a PR.

  1. The simplest would be to allow a trusted header that would be set by the reverse proxy with the authenticated user ID (probably email address, but maybe username). The login process of lemmy would check if this header is set, and if so authenticate and set the jwt cookie appropriately.

  2. The reverse proxy could use middleware to authenticate the user and set a jwt token as an authorization header or maybe in the jwt cookie. Lemmy could check these two locations for a valid jwt token and authenticate the session, populating the rest of the cookie. This of course would mean that the jwt secret would be shared between the middleware and lemmy, allowing the signatures to validate.

Thanks for the consideration!

@dessalines
Copy link
Member

I'm sure some other people could chime in, because I don't know how the middle layer would function. But the easiest way would be to use the http API, and create a user with the correct user / pass, and it'll give you the auth / jwt token, which you can then pass to the user.

You might even be able to do the blocking with nginx, but I'm not too knowledgeable on how it would work. Lemmy itself uses no headers, just a single jwt / auth string, and all authenticated requests require the auth token which the front end pulls from your cookies.

@dessalines dessalines added extra: help wanted Extra attention is needed type: discussion General talk without any clear action labels Feb 3, 2020
@nikhiljha
Copy link

Using SAML/OAuth/OpenID as an authentication mechanism and then issuing a token from Lemmy's side would be great too. This is how most apps I've deployed work. Alternatively, (a) requiring email confirmation and (b) requiring emails to be [email protected] would work for a lot of orgs.

@dessalines
Copy link
Member

I don't have time for this one in the near future, but if anyone wants to have a go at it, go right ahead.

@poVoq
Copy link

poVoq commented Oct 27, 2020

Oauth2 / OpenID Connect is the way to go and would allow Lemmy to link to account providers like Gitea or Nextcloud easily.

There are some nice rust client libraries for it too.

@ccoenen
Copy link

ccoenen commented Nov 28, 2020

@dessalines would you still be open to contributions regarding OAuth?

@dessalines
Copy link
Member

Of course, I just personally don't have time to do them.

@decentral1se
Copy link

If anyone makes a start at implementing this I'd glady support with testing it!

@mogui
Copy link

mogui commented May 24, 2022

Hi guys, I'll gladly help with this, since i need it bad.
But I don't know where to start to implement it. From what I see in the code there is no a central place where auth is managed. Can someone point me out how could it be achieved?

@dessalines
Copy link
Member

Check out the get_local_user_from_jwt function for reading the auth from the requests, and the LocalUser::register function for creating users.

@mogui
Copy link

mogui commented May 24, 2022

Thanks!
Ok to get user from request, but the point with an Oauth flow is that user are NOT registered, the entire login flow should change.
going to login endpoint should redirect to the oauth provider. I think this is a cross work with the UI?

@dessalines
Copy link
Member

dessalines commented May 24, 2022

I'm not too familiar with oauth, but using a third party login still means that the first oauth request would have to create a lemmy account. No idea how that would work with registration applications and all that.

@mogui
Copy link

mogui commented May 24, 2022

mmmh I've never implemented such a flow, I have to think about how to do it.
Lemmy won't work without a proper Lemmy account entity in db ?

@dessalines
Copy link
Member

Correct. You need to have an account.

I think ppl are talking about two different things here.

  • Implementing a Lemmy Oauth service, so that 3rd party apps can use that to get a JWT. IE for 3rd party lemmy apps.
  • Using other 3rd party Oauth services like google or github to create an account and log in to lemmy.

@erlend-sh
Copy link

@dessalines
Copy link
Member

Dupe of #2930 , #1368

@dessalines dessalines closed this as not planned Won't fix, can't repro, duplicate, stale May 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: auth extra: help wanted Extra attention is needed type: discussion General talk without any clear action
Projects
None yet
Development

No branches or pull requests

9 participants