django-saml2-auth
django-saml2-auth copied to clipboard
Configurable authentication backend
Currently, the authentication backend passed to the django.contrib.auth.login
method is hard-coded to "django.contrib.auth.backends.ModelBackend"
. This makes it impossible to use this library if you use any other authentication backend, e.g. a custom one. Since the django settings dict is already imported in views.py
, one implementation method could be to replace the hard-coded line with
model_backend = dictor(
settings,
"AUTHENTICATION_BACKENDS.0",
default="django.contrib.auth.backends.ModelBackend"
)
This will look at the current list of authentication backends defined in settings.py
and return the first one from the list.
I'm forking the repo to do this, as I need this functionality right now, but I'll open a PR back into this repo once it's ready for primetime.
Also, thanks for adopting the abandoned library @mostafa!
Ahh, looks like dictor
doesn't like the settings object, but this works
if hasattr(settings, "AUTHENTICATION_BACKENDS") and settings.AUTHENTICATION_BACKENDS:
model_backend = settings.AUTHENTICATION_BACKENDS[0]
else:
model_backend = "django.contrib.auth.backends.ModelBackend"
Hey @henxing,
thanks for your contribution. What is the problem with dictor
here?
I was just saying that my initial suggested code snipped didn't work because dictor
works on dictionaries, but settings
is a module with attributes, hence the use of hasattr
in my second suggestion and pull request.
@henxing Fair enough! I don't see the CLA here. Let me fix that and I'll get back to you.
Which means you need to sign the CLA before I can merge your PR.
No problem, I thought I filled it out, but I'll go do it now.
Yeah, if I go to https://cla-assistant.io/grafana/django-saml2-auth?pullRequest=73
and log in with GitHub, it tells me I've already signed it. If this isn't the correct way to do that, please let me know. And thanks!
@henxing But this is PR #72. 🤔
Whoops, sorry, I copied the link from a different pr and just changed the number when I pasted it in my browser, I forgot to change the number when I wrote that comment. I do notice that my pr doesn't have any mention of the CLA like #73 does, so maybe there's something wrong with cla assistant?
Ah, there we go, I forced a recheck with cla assistant and that seems to have done the trick.