Skip to content

Commit 198fe81

Browse files
author
lijianguo
committed
chore(oauth): modify token Authentication
1 parent ffef586 commit 198fe81

1 file changed

Lines changed: 5 additions & 8 deletions

File tree

rootfs/api/authentication.py

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -55,13 +55,12 @@ def authenticate(self, request):
5555
except UnicodeError:
5656
msg = _('Invalid token header. Token string should not contain invalid characters.') # noqa
5757
raise exceptions.AuthenticationFailed(msg)
58-
return self._check_oauth_token(token)
58+
return cache.get_or_set(
59+
token, lambda: self._get_user(token), settings.OAUTH_CACHE_USER_TIME), None # noqa
5960
return super(DryccTokenAuthentication, self).authenticate(request) # noqa
6061

61-
def _check_oauth_token(self, key):
62-
user = cache.get(key)
63-
if user:
64-
return user, None
62+
@staticmethod
63+
def _get_user(key):
6564
try:
6665
user_info = OAuthManager().get_user_by_token(key)
6766
if not user_info.get('email'):
@@ -70,6 +69,4 @@ def _check_oauth_token(self, key):
7069
logger.info(e)
7170
raise exceptions.AuthenticationFailed(_('Verify token fail.'))
7271
from api import serializers
73-
user = serializers.UserSerializer.update_or_create(user_info)
74-
cache.set(key, user, settings.OAUTH_USER_CACHE_TIME)
75-
return user, None
72+
return serializers.UserSerializer.update_or_create(user_info)

0 commit comments

Comments
 (0)