Skip to content

Commit

Permalink
Merge pull request #1689 from unicef/fix-token-auth
Browse files Browse the repository at this point in the history
Token auth now also checks against drf token auth
  • Loading branch information
robertavram authored Jul 2, 2018
2 parents c7be0f0 + 1bf624d commit 56afabe
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/etools/applications/tokens/middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
from django.utils.deprecation import MiddlewareMixin

from drfpasswordless.utils import authenticate_by_token
from rest_framework.authentication import TokenAuthentication
from rest_framework.exceptions import AuthenticationFailed


class TokenAuthenticationMiddleware(MiddlewareMixin):
Expand All @@ -11,7 +13,14 @@ def process_request(self, request):
if token is None:
return

user = authenticate_by_token(token)
try:
# attempt to auth via authtoken
token_auth = TokenAuthentication()
user, _ = token_auth.authenticate_credentials(token)
except AuthenticationFailed:
# attempt to auth by drfpasswordless
user = authenticate_by_token(token)

if user is None:
return

Expand Down

0 comments on commit 56afabe

Please sign in to comment.