vimalloc / vimalloc/flask-jwt-extended

Having trouble with refresh tokens

Open
#569 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
1.6k
Forks
253
PR merge metrics
No merged PRs in 30d

Description

I'm attempting to follow the instructions here: https://flask-jwt-extended.readthedocs.io/en/stable/refreshing_tokens.html for explicitly refreshing tokens.

I use:

 @app.before_request
    def beforeRequest():
         ...
         try
          ...
          except ExpiredSignatureError:
                abort(401, description="expired token") 

to capture expired tokens.

On the client side I am able to respond to this error and I call a refresh

@loginNamespace.route("/refresh", methods=["POST"])
class Refresh(Resource):

    # We are using the `refresh=True` options in jwt_required to only allow
    # refresh tokens to access this route.
    @jwt_required(refresh=True, locations= ["headers"])
    def post(self):
        identity = get_jwt_identity()
        access_token = create_access_token(identity=identity)
        return {"access_token": access_token}, 200

per the documentation.

I use this new access_token in my subsequent request to the protected resource and I get a 500 error indicating that the token that I am using is not the correct format:

binascii.Error: Invalid base64-encoded string: number of data characters (369) cannot be 1 more than a multiple of 4

It is unclear to me what I am supposed to be doing with the new access token that is created. I suppose it is possible that the refresh token itself is expired, but I would have exited the creation of the new access token to fail.

thanks in advance.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the refreshing tokens documentation and compare the /refresh endpoint response with how the client supplies the new access token to the protected resource. Reproduce the base64 decoding error, then verify that the refresh flow and subsequent authenticated request handle the generated token consistently.

Written by the indexing model from the issue text.

Assessment

Tech stack
flask, python
Domain
api, authentication, backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.