I am writing webapp in Angular where authentication is performed using a JWT token, which means that each request has an “Authentication” header with all the necessary information.
This works well for REST calls, but I don’t understand how I should handle links to upload files hosted on the backend (the files are on the same server as the web services).
I can’t use regular links <a href='...'/> , since they will not have any header and authentication will fail. The same goes for the various window.open(...) spells.
Some solutions I was thinking about:
- Create a temporary insecure download link on the server
- Pass authentication information as url parameter and handle this case manually
- Get data through XHR and save the client part of the file.
All of the above is less satisfactory.
1 is the solution I'm using right now. I don’t like this for two reasons: firstly, it’s not perfect security, and secondly, it works, but it requires a lot of work, especially on the server: load something that I need, call the service that generates a new "random" url, somewhere stores it (possibly in the database) and returns it to the client. The client receives the URL and uses window.open or similar. When requested, the new URL should check if it is valid and then return the data.
2 seems at least the same job.
3 seems like a lot of work, even with the use of accessible libraries and many potential problems. (I will need to provide my own boot status bar, load the entire file into memory, and then ask the user to save the file locally).
The task seems pretty simple, so I wonder if there is something much simpler that I can use.
I'm not necessarily looking for an Angular Way solution. Normal Javascript will be fine.
javascript angularjs jwt
Marco Righele Apr 04 '15 at 22:21 2015-04-04 22:21
source share