moiseshiraldo / django-rest-paseto-auth

PASETO authentication for Django REST framework
MIT License
7 stars 1 forks source link

Invalid Key error #5

Open saurav-codes opened 1 year ago

saurav-codes commented 1 year ago

After doing all config for the package, I rec-d the below error.

Environment:

Request Method: POST
Request URL: http://localhost:8000/api/auth/token/

Django Version: 3.2.16
Python Version: 3.8.0
Installed Applications:
['django.contrib.admin',
 'django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.messages',
 'whitenoise.runserver_nostatic',
 'django.contrib.staticfiles',
 'django_extensions',
 'rest_framework',
 'paseto_auth',
 'haystack',
 'apps.core',
 'debug_toolbar']
Installed Middleware:
['django.middleware.security.SecurityMiddleware',
 'whitenoise.middleware.WhiteNoiseMiddleware',
 'django.contrib.sessions.middleware.SessionMiddleware',
 'django.middleware.common.CommonMiddleware',
 'debug_toolbar.middleware.DebugToolbarMiddleware',
 'django.middleware.csrf.CsrfViewMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'django.contrib.messages.middleware.MessageMiddleware',
 'django.middleware.clickjacking.XFrameOptionsMiddleware']

Traceback (most recent call last):
  File "/home/saurav/projects/djangoflix/env/lib/python3.8/site-packages/django/core/handlers/exception.py", line 47, in inner
    response = get_response(request)
  File "/home/saurav/projects/djangoflix/env/lib/python3.8/site-packages/django/core/handlers/base.py", line 181, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "/home/saurav/projects/djangoflix/env/lib/python3.8/site-packages/django/views/decorators/csrf.py", line 54, in wrapped_view
    return view_func(*args, **kwargs)
  File "/home/saurav/projects/djangoflix/env/lib/python3.8/site-packages/django/views/generic/base.py", line 70, in view
    return self.dispatch(request, *args, **kwargs)
  File "/home/saurav/projects/djangoflix/env/lib/python3.8/site-packages/rest_framework/views.py", line 509, in dispatch
    response = self.handle_exception(exc)
  File "/home/saurav/projects/djangoflix/env/lib/python3.8/site-packages/rest_framework/views.py", line 469, in handle_exception
    self.raise_uncaught_exception(exc)
  File "/home/saurav/projects/djangoflix/env/lib/python3.8/site-packages/rest_framework/views.py", line 480, in raise_uncaught_exception
    raise exc
  File "/home/saurav/projects/djangoflix/env/lib/python3.8/site-packages/rest_framework/views.py", line 506, in dispatch
    response = handler(request, *args, **kwargs)
  File "/home/saurav/projects/djangoflix/env/lib/python3.8/site-packages/paseto_auth/views.py", line 31, in post
    serializer.is_valid(raise_exception=True)
  File "/home/saurav/projects/djangoflix/env/lib/python3.8/site-packages/rest_framework/serializers.py", line 220, in is_valid
    self._validated_data = self.run_validation(self.initial_data)
  File "/home/saurav/projects/djangoflix/env/lib/python3.8/site-packages/rest_framework/serializers.py", line 422, in run_validation
    value = self.validate(value)
  File "/home/saurav/projects/djangoflix/env/lib/python3.8/site-packages/paseto_auth/serializers.py", line 54, in validate
    tokens = self.get_tokens(data)
  File "/home/saurav/projects/djangoflix/env/lib/python3.8/site-packages/paseto_auth/serializers.py", line 71, in get_tokens
    access_token = AccessToken(data=self.claims)
  File "/home/saurav/projects/djangoflix/env/lib/python3.8/site-packages/paseto_auth/tokens.py", line 55, in __init__
    self._create_token()
  File "/home/saurav/projects/djangoflix/env/lib/python3.8/site-packages/paseto_auth/tokens.py", line 65, in _create_token
    token = paseto.create(
  File "/home/saurav/projects/djangoflix/env/lib/python3.8/site-packages/paseto/paseto.py", line 75, in create
    raise ValueError("invalid key")

Exception Type: ValueError at /api/auth/token/
Exception Value: invalid key

Can anyone pls help on this.

moiseshiraldo commented 1 year ago

It seems the error is coming from the paseto library complaining about an invalid key. Could you check that the value of settings.PASETO_KEY is set correctly in Django to some 32-bytes hexadecimal secret key?

I wouldn't recommend using this library anyway unless you're just playing with it for dev purposes, as I'm not really maintaining it.

saurav-codes commented 1 year ago

yeah, I have set the settings.PASETO_KEY to a 32-byte hexadecimal value. but still it's giving error. also I want to use this library for production project but like you said, you are not maintaining it, now I am using the python pyseto.