Browse Source

[api] Add a auto login flag for testing purpose (#2038)

And to decouple it from the CORS off flag.
Romain Rigaux 4 years ago
parent
commit
a601b1472b
2 changed files with 8 additions and 2 deletions
  1. 7 1
      desktop/core/src/desktop/conf.py
  2. 1 1
      desktop/core/src/desktop/middleware.py

+ 7 - 1
desktop/core/src/desktop/conf.py

@@ -1178,7 +1178,13 @@ AUTH = ConfigSection(
       help=_("If behind_reverse_proxy is True, it will look for the IP address from this header. Default: HTTP_X_FORWARDED_FOR"),
       help=_("If behind_reverse_proxy is True, it will look for the IP address from this header. Default: HTTP_X_FORWARDED_FOR"),
       type=str,
       type=str,
       default="HTTP_X_FORWARDED_FOR",
       default="HTTP_X_FORWARDED_FOR",
-    )
+    ),
+    AUTO_LOGIN_ENABLED=Config(
+      key="auto_login_enabled",
+      help=_("If True, will auto log any request as a `hue` user that needs to exist."),
+      type=coerce_bool,
+      default=False,
+    ),
 ))
 ))
 
 
 
 

+ 1 - 1
desktop/core/src/desktop/middleware.py

@@ -358,7 +358,7 @@ class LoginAndPermissionMiddleware(MiddlewareMixin):
           log_page_hit(request, view_func, level=access_log_level)
           log_page_hit(request, view_func, level=access_log_level)
         return None
         return None
 
 
-    if desktop.conf.CORS_ENABLED.get():
+    if AUTH.AUTO_LOGIN_ENABLED.get():
       user = authenticate(request, username='hue', password='hue')
       user = authenticate(request, username='hue', password='hue')
       if user is not None:
       if user is not None:
         login(request, user)
         login(request, user)