- I have a file, served with flask, protected with token based authentication.
- I want to offer a download to it from an angular app
- the token is stored in the angular session and put into the header of each $http.get or post
But when I just place a link to the flask path, the token is not added in the request header since it is no angular $http.get() but just an ordinary anchor I cannot do this (right?).
I dont want to pass the token in the url as query string parameter. How do I offer the dowload to the user? Should I first $http.get() it into angular and then tunnel it through as a file download?
Token storage after login:
$window.sessionStorage.token = results.response.user.authentication_token;
It is injected in each $http get or post:
config.headers['Authentication-Token'] = $window.sessionStorage.getItem('token');
Flask (with flask-security) part:
@app.route("/download", methods=['GET'])
@auth_token_required
def download():
response = make_response(open('filename.ext').read())
response.headers["Content-Disposition"] = "attachment; filename=download.ext"
return response
How do I solve this?