a-luna / flask-api-tutorial

Boilerplate for a Flask REST API with JWT-based authentication, built with SQLAlchemy, Flask-RESTx, PyJWT, and pytest. This is a companion repo for a multi-part tutorial series on my personal website.
https://aaronluna.dev/series/flask-api-tutorial/overview/
74 stars 18 forks source link

PyJWT encode return type has changed #7

Open sean-bytefoundry opened 3 years ago

sean-bytefoundry commented 3 years ago

As of version 2.0, the return type for jwt.encode is string instead of byte string, causing encode and decode tests to fail.

jaytaytay commented 2 years ago

After reading this I've added these 3 lines to the end of encode_access_token in models.user.py

    token = jwt.encode(payload, key, algorithm="HS256")
    if isinstance(token, str):
        token = token.encode("UTF-8")

which resolved this issue for me. Perhaps it has introduced new issues, hope not!