volatiletech / authboss

The boss of http auth.
MIT License
3.79k stars 204 forks source link

Don't allow registration with OAuth2 #341

Closed Bo0mer closed 1 year ago

Bo0mer commented 2 years ago

Hi,

First of all thanks for your awesome work!

I have use case where I wan't to allow sign in with OAuth2 for existing application users, but I don't want to allow new registrations (the registration process happens manually by an administrator). However, I'm not sure how I can achieve that. I've looked at the code of the OAuth2 module and I noticed that there is no event fired before attempting to save the user into the OAuth2ServerStorer:

https://github.com/volatiletech/authboss/blob/e74112f6170d67dafda5c9a9033bda38cd9df4e5/oauth2/oauth2.go#L235-L249

The only solution I see is to implement my own OAuth2 module that fires an event prior to saving the user. In the event handler I'll check whether the user exists, and if it does not, I'll stop the execution of the OAuth2 module (effectively skip saving user into the store).

Other option I see is to have a custom OAuth2 module that handles specific error returned from the OAuth2ServerStorer.SaveOAuth2 and again skip persisting the user.

I like the first approach better, but still I wanted to hear whether this is something that anyone else has considered and if it will eventually fit into authboss itself.

Best, Ivan

aarondl commented 1 year ago

Hi Ivan, I haven't considered this one before. The event seems a bit strange as it's a sort of bail out event which is more rare.

It's considered a fine practice to fork these modules, they don't change much at this time so I wouldn't hesitate.