Bläddra i källkod

Fixes #11977: Multiple remote authentication backends (#12012)

* Add suppport for REMOTE_AUTH_BACKEND as iterable

* Closes #11977: Support for multiple auth backends

* Tweak list casting

---------

Co-authored-by: jeremystretch <jstretch@netboxlabs.com>
Austin de Coup-Crank 2 år sedan
förälder
incheckning
2eedcac383
2 ändrade filer med 4 tillägg och 2 borttagningar
  1. 1 1
      docs/configuration/remote-authentication.md
  2. 3 1
      netbox/netbox/settings.py

+ 1 - 1
docs/configuration/remote-authentication.md

@@ -16,7 +16,7 @@ If true, NetBox will automatically create local accounts for users authenticated
 
 
 Default: `'netbox.authentication.RemoteUserBackend'`
 Default: `'netbox.authentication.RemoteUserBackend'`
 
 
-This is the Python path to the custom [Django authentication backend](https://docs.djangoproject.com/en/stable/topics/auth/customizing/) to use for external user authentication. NetBox provides two built-in backends (listed below), though custom authentication backends may also be provided by other packages or plugins.
+This is the Python path to the custom [Django authentication backend](https://docs.djangoproject.com/en/stable/topics/auth/customizing/) to use for external user authentication. NetBox provides two built-in backends (listed below), though custom authentication backends may also be provided by other packages or plugins. Provide a string for a single backend, or an iterable for multiple backends, which will be attempted in the order given.
 
 
 * `netbox.authentication.RemoteUserBackend`
 * `netbox.authentication.RemoteUserBackend`
 * `netbox.authentication.LDAPBackend`
 * `netbox.authentication.LDAPBackend`

+ 3 - 1
netbox/netbox/settings.py

@@ -396,8 +396,10 @@ TEMPLATES = [
 ]
 ]
 
 
 # Set up authentication backends
 # Set up authentication backends
+if type(REMOTE_AUTH_BACKEND) not in (list, tuple):
+    REMOTE_AUTH_BACKEND = [REMOTE_AUTH_BACKEND]
 AUTHENTICATION_BACKENDS = [
 AUTHENTICATION_BACKENDS = [
-    REMOTE_AUTH_BACKEND,
+    *REMOTE_AUTH_BACKEND,
     'netbox.authentication.ObjectPermissionBackend',
     'netbox.authentication.ObjectPermissionBackend',
 ]
 ]