Browse Source

[jwt] Allow developers test API calls without token in local dev env (#2460)

Ying Chen 4 years ago
parent
commit
589358d0d5
1 changed files with 13 additions and 0 deletions
  1. 13 0
      desktop/core/src/desktop/auth/api_authentications.py

+ 13 - 0
desktop/core/src/desktop/auth/api_authentications.py

@@ -81,3 +81,16 @@ class JwtAuthentication(authentication.BaseAuthentication):
       user.profile.save()
 
     return (user, None)
+
+
+# for local dev env doesn't have authentication service
+class DummyCustomAuthentication(authentication.BaseAuthentication):
+
+  def authenticate(self, request):
+    LOG.debug('DummyCustomAuthentication: %s' % request.path)
+    user = find_or_create_user(username='hue', password='hue')
+    ensure_has_a_group(user)
+    user = rewrite_user(user)
+    user.is_active = True
+
+    return (user, None)