1

This is how my login method looks like:

def login(): if request.method == "GET": return render_template('user/login.html') else: jwt_token = "xxxx" resp = redirect(url_for('home.index')) resp.headers.set('Authorization', "JWT {}".format(jwt_token)) return resp 

This works fine but the Authorization header does not make it to home.index page.

How do I tell flask to preserve this header on every request?

------Edit---------

This works if I add Token to Cookie as resp.set_cookie('Authorization', "JWT {}".format(json_data["access_token"])) but I would like to keep it in the Authorization Header.

1 Answer 1

2

If you want to set Authorization header on all requests, you could do something like this:

@app.after_request def after_request(response): my_jwt_token = 'xxxx' response.headers['Authorization'] = my_jwt_token return response 

More information on documentation: http://flask.pocoo.org/docs/1.0/api/#flask.Flask.after_request

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.