PedroBern / django-graphql-auth

Django registration and authentication with GraphQL.

Home Page:https://django-graphql-auth.readthedocs.io/en/latest/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

PyJWT 2.0 Results in Decoding Error on Mutation

aecallahan opened this issue · comments

Prerequisites

  • Is it a bug?
  • Is it a new feature?
  • Is it a a question?
  • Can you reproduce the problem?
  • Are you running the latest version?
  • Did you check for similar issues?
  • Did you perform a cursory search?

Description

Mutations are incompatible with PyJWT 2.0

Steps to Reproduce

I started using this library for user registration, it's quite nice! After following the quick start instructions I had everything working up until the part on creating new users with mutations. I believe I followed all the instructions to the letter but I was getting this error:

Traceback (most recent call last):
  File "/usr/local/lib/python3.8/site-packages/promise/promise.py", line 489, in _resolve_from_executor
    executor(resolve, reject)
  File "/usr/local/lib/python3.8/site-packages/promise/promise.py", line 756, in executor
    return resolve(f(*args, **kwargs))
  File "/usr/local/lib/python3.8/site-packages/graphql/execution/middleware.py", line 75, in make_it_promise
    return next(*args, **kwargs)
  File "/usr/local/lib/python3.8/site-packages/graphql_auth/bases.py", line 31, in mutate
    return cls.resolve_mutation(root, info, **input)
  File "/usr/local/lib/python3.8/site-packages/graphql_auth/mixins.py", line 122, in resolve_mutation
    payload = cls.login_on_register(
  File "/usr/local/lib/python3.8/site-packages/graphql_jwt/decorators.py", line 110, in wrapper
    result = f(cls, root, info, **kwargs)
  File "/usr/local/lib/python3.8/site-packages/graphql_jwt/decorators.py", line 103, in wrapper
    return on_resolve(values)
  File "/usr/local/lib/python3.8/site-packages/graphql_jwt/decorators.py", line 74, in on_resolve
    payload.token = get_token(user, context)
  File "/usr/local/lib/python3.8/site-packages/graphql_jwt/shortcuts.py", line 16, in get_token
    return jwt_settings.JWT_ENCODE_HANDLER(payload, context)
  File "/usr/local/lib/python3.8/site-packages/graphql_jwt/utils.py", line 37, in jwt_encode
    return jwt.encode(
graphql.error.located_error.GraphQLLocatedError: 'str' object has no attribute 'decode'

After looking through the project's requirements file and comparing it to my installed packages, I found that downgrading my PyJWT from 2.0 to 1.7.1 fixes the issue. I think it would be helpful to mention this requirement to use a specific PyJWT version in the installation guide to help others avoid this pitfall.

Expected behavior

No 'decode' issues when creating new users.

Actual behavior

graphql.error.located_error.GraphQLLocatedError: 'str' object has no attribute 'decode' if using PyJWT 2.0

Requirements

Paste the packages you are using, you can get this information from executing pip freeze.

aniso8601==7.0.0
asgiref==3.3.1
Django==3.1.5
django-cors-headers==3.6.0
django-filter==2.4.0
django-graphql-auth==0.3.15
django-graphql-jwt==0.3.0
graphene==2.1.8
graphene-django==2.15.0
graphql-core==2.3.2
graphql-relay==2.0.1
promise==2.3
psycopg2-binary==2.8.6
PyJWT==2.0.0
pytz==2020.5
Rx==1.6.1
singledispatch==3.4.0.3
six==1.15.0
sqlparse==0.4.1
text-unidecode==1.3