-
Notifications
You must be signed in to change notification settings - Fork 56
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
Discussion: what is the benefit of going through the authentication backend system? #107
Comments
The pattern you are showing ( Providing a custom authentication backend is the recommended way to authenticate against another source in Django: https://docs.djangoproject.com/en/stable/topics/auth/customizing/ It is also necessary for authenticate() to work as documented. That being said, some use cases can work without the authentication backend. You can remove it from your configuration. If all API you need still work, I think you're good to go. I'm going to take a deeper look at this. I'm keeping it open as a documentation issue. |
Wait - get_user() calls authenticate() so nothing will work without the authentication backend. |
Right, it's currently needed as is. But really, the meat of the library is in So just doing I guess I see custom backends as "authenticating against another source" where source is "active directory" or "SSO" or "something other than a local DB table". Here's simplified pseudo code for from django.contrib.auth import login
def get_user(request_or_sesame, scope="", max_age=None, *, update_last_login=None):
# ... setup logic
if user := parse_token(...args):
login(
request,
user,
)
if update_last_login is None:
update_last_login = settings.ONE_TIME
if update_last_login:
user.last_login = timezone.now()
user.save(update_fields=["last_login"])
return user Either way, library works great as is. Just looking to simplify the setup (since |
I'm not sure I will do something but I'd like to think a bit more about it :-) I'm keeping it open for myself. Thanks for sharing that feedback! |
Another thing to consider might be that by simply calling |
I was surprised when setting up this library that you needed an additional auth backend.
I've hacked together versions of this before (far less sophisticated) and ultimately just parse the token and call
django.contrib.auth.login
directly on the user if the token is valid.I'd say it's not a big deal, but noticed now I have to pass a backend to
login
every time I do it for other purposes. Say, after registering or in my login-as-other-user tools. Things outside sesame.Couldn't this library just parse the token as it currently does then directly call
login
without going through the backend chain?Eases the setups — only decorators required — and allows
login
to keep working for other purposes.For reference,
After configuring django-sesame:
The text was updated successfully, but these errors were encountered: