1

Config

app.config['JWT_COOKIE_CSRF_PROTECT'] = True
app.config["JWT_TOKEN_LOCATION"] = ['cookies']
app.config["JWT_ACCESS_TOKEN_EXPIRES"] = timedelta(hours=0.005)

class LogOut(Resource):
    @jwt_required()
    def get(self):
        response = make_response(render_template('home.html', is_login=False))
        unset_jwt_cookies(response)
        return response


@app.after_request
def refresh_expiring_jwts(response):
    try:
        exp_timestamp = get_jwt()["exp"]
        now = datetime.now(timezone.utc)
        target_timestamp = datetime.timestamp(now + timedelta(minutes=30))
        if target_timestamp > exp_timestamp:
            access_token = create_access_token(identity=get_jwt_identity())
            set_access_cookies(response, access_token)
        return response
    except (RuntimeError, KeyError):
        # Case where there is not a valid JWT. Just return the original respone
        return response

I am trying to write code for implict refresh of access tokens using Flask-JWT-Extended library and having the below error.

In the above code login is working properly but if we access the logout the access token cookies are not being deleted.

Can anyone explain why it is not working?

private123
  • 11
  • 1
  • This may not be helpful, but I had a similar issue where 1 out of roughly 10 times i tried to logout it actually worked. So in my app's frontend I just make the 'get' request to logout 20 times and it works. – Jeffyx Jun 08 '22 at 15:35

0 Answers0