|
|
@@ -21,6 +21,7 @@ import jwt
|
|
|
from rest_framework import authentication, exceptions
|
|
|
|
|
|
from desktop.auth.backend import find_or_create_user, ensure_has_a_group, rewrite_user
|
|
|
+from desktop.conf import ENABLE_ORGANIZATIONS
|
|
|
|
|
|
from useradmin.models import User
|
|
|
|
|
|
@@ -31,11 +32,17 @@ class JwtAuthentication(authentication.BaseAuthentication):
|
|
|
|
|
|
def authenticate(self, request):
|
|
|
authorization_header = request.META.get('HTTP_AUTHORIZATION')
|
|
|
+
|
|
|
if not authorization_header:
|
|
|
LOG.debug('JwtAuthentication: no authorization header')
|
|
|
return None
|
|
|
|
|
|
- access_token = authorization_header[len('Bearer '):]
|
|
|
+ header, access_token = authorization_header.split(' ')
|
|
|
+
|
|
|
+ if header != 'Bearer':
|
|
|
+ LOG.debug('JwtAuthentication: no Bearer header')
|
|
|
+ return None
|
|
|
+
|
|
|
if not access_token:
|
|
|
LOG.debug('JwtAuthentication: no Bearer value')
|
|
|
return None
|
|
|
@@ -55,12 +62,11 @@ class JwtAuthentication(authentication.BaseAuthentication):
|
|
|
ensure_has_a_group(user)
|
|
|
user = rewrite_user(user)
|
|
|
|
|
|
- # We should persist the token (to reuse for communicating with external services as the user, e.g. Impala)
|
|
|
- # either via a new DB field (might just be cleaner, even if requires a DB migration) or in the json blob.
|
|
|
- # if ENABLE_ORGANIZATIONS.get():
|
|
|
- # user.token = token
|
|
|
- # else:
|
|
|
- # user.profile.update_data({'token': token})
|
|
|
- # user.profile.save()
|
|
|
+ # Persist the token (to reuse for communicating with external services as the user, e.g. Impala)
|
|
|
+ if ENABLE_ORGANIZATIONS.get():
|
|
|
+ user.token = access_token
|
|
|
+ else:
|
|
|
+ user.profile.update_data({'jwt_access_token': access_token})
|
|
|
+ user.profile.save()
|
|
|
|
|
|
return (user, None)
|