Hi all,
I'm developing a Django application for Windows with Pyhton 2.7.15. I need 
to implement an authentication mechanism with Django REST Framework JWT 
<https://getblimp.github.io/django-rest-framework-jwt/> where I simply need 
to verify a token (and not to generate it). The token's payload is 
something like this:

{
  "iss": "customIssuer",
  "username": "customUser"
}

For this reason, I configure my setting.py in this way:

...

REST_FRAMEWORK = {
    'DEFAULT_PERMISSION_CLASSES': (
        'rest_framework.permissions.IsAuthenticated',
    ),
    'DEFAULT_AUTHENTICATION_CLASSES': (
        'rest_framework_jwt.authentication.JSONWebTokenAuthentication',
        'rest_framework.authentication.TokenAuthentication'
    ),
}


JWT_AUTH = {
    'JWT_ISSUER': 'customIssuer'
}


...

and my urls.py in this way:

...


from rest_framework_jwt.views import verify_jwt_token


urlpatterns = [
    ...
    url(r'^api-token-verify/', verify_jwt_token),
    ...
]

Then, if I try to send a POST request with the above token, I get this 
error:

Traceback (most recent call last):
  File 
"C:\Software\Workspace\py2_env\lib\site-packages\django\core\handlers\exception.py"
, line 41, in inner
    response = get_response(request)
  File 
"C:\Software\Workspace\py2_env\lib\site-packages\django\core\handlers\base.py"
, line 187, in _get_response
    response = self.process_exception_by_middleware(e, request)
  File 
"C:\Software\Workspace\py2_env\lib\site-packages\django\core\handlers\base.py"
, line 185, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File 
"C:\Software\Workspace\py2_env\lib\site-packages\django\views\decorators\csrf.py"
, line 58, in wrapped_view
    return view_func(*args, **kwargs)
  File 
"C:\Software\Workspace\py2_env\lib\site-packages\django\views\generic\base.py"
, line 68, in view
    return self.dispatch(request, *args, **kwargs)
  File 
"C:\Software\Workspace\py2_env\lib\site-packages\rest_framework\views.py", 
line 489, in dispatch
    response = self.handle_exception(exc)
  File 
"C:\Software\Workspace\py2_env\lib\site-packages\rest_framework\views.py", 
line 449, in handle_exception
    self.raise_uncaught_exception(exc)
  File 
"C:\Software\Workspace\py2_env\lib\site-packages\rest_framework\views.py", 
line 486, in dispatch
    response = handler(request, *args, **kwargs)
  File 
"C:\Software\Workspace\py2_env\lib\site-packages\rest_framework_jwt\views.py"
, line 57, in post
    if serializer.is_valid():
  File 
"C:\Software\Workspace\py2_env\lib\site-packages\rest_framework\serializers.py"
, line 237, in is_valid
    self._validated_data = self.run_validation(self.initial_data)
  File 
"C:\Software\Workspace\py2_env\lib\site-packages\rest_framework\serializers.py"
, line 435, in run_validation
    value = self.validate(value)
  File 
"C:\Software\Workspace\py2_env\lib\site-packages\rest_framework_jwt\serializers.py"
, line 130, in validate
    user = self._check_user(payload=payload)
  File 
"C:\Software\Workspace\py2_env\lib\site-packages\rest_framework_jwt\serializers.py"
, line 109, in _check_user
    user = User.objects.get_by_natural_key(username)
  File 
"C:\Software\Workspace\py2_env\lib\site-packages\django\contrib\auth\base_user.py"
, line 48, in get_by_natural_key
    return self.get(**{self.model.USERNAME_FIELD: username})
  File 
"C:\Software\Workspace\py2_env\lib\site-packages\django\db\models\manager.py"
, line 85, in manager_method
    return getattr(self.get_queryset(), name)(*args, **kwargs)
  File 
"C:\Software\Workspace\py2_env\lib\site-packages\django\db\models\query.py", 
line 374, in get
    num = len(clone)
  File 
"C:\Software\Workspace\py2_env\lib\site-packages\django\db\models\query.py", 
line 232, in __len__
    self._fetch_all()
  File 
"C:\Software\Workspace\py2_env\lib\site-packages\django\db\models\query.py", 
line 1105, in _fetch_all
    self._result_cache = list(self._iterable_class(self))
  File 
"C:\Software\Workspace\py2_env\lib\site-packages\django\db\models\query.py", 
line 53, in __iter__
    results = compiler.execute_sql(chunked_fetch=self.chunked_fetch)
  File 
"C:\Software\Workspace\py2_env\lib\site-packages\django\db\models\sql\compiler.py"
, line 886, in execute_sql
    raise original_exception
OperationalError: no such table: auth_user

Checking the "rest framework jwt" package, I notice that this error is 
throw by serializers.py. In particular from the check_user method:

def _check_user(self, payload):


    username = jwt_get_username_from_payload(payload)


    if not username:
        msg = _('Invalid payload.')
        raise serializers.ValidationError(msg)


    # Make sure user exists
    try:
        user = User.objects.get_by_natural_key(username) # <========= 
ERROR!!!!
    except User.DoesNotExist:
        msg = _("User doesn't exist.")
        raise serializers.ValidationError(msg)


    if not user.is_active:
        msg = _('User account is disabled.')
        raise serializers.ValidationError(msg)


    return user

-- 
You received this message because you are subscribed to the Google Groups 
"Django REST framework" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-rest-framework+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to