从前preSS下载文件的Node.js与智威汤逊授权 [英] Download file from express node.js with JWT authorization

查看:105
本文介绍了从前preSS下载文件的Node.js与智威汤逊授权的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用我的node.js服务器上的前preSS-智威汤逊模块授权的用户访问不同的请求。其中一个请求最终将文件下载与前preSS res.download(文件)。

I'm using the express-jwt module on my node.js server to authorize users access to different requests. One of the request will ultimately be a file download with express res.download(file).

问题是,我不能这样做,因为我通常会通过AJAX的要求去做(角$ http.get),因为这不会触发在浏览器所需要的文件下载弹出。没有Ajax虽然(window.open),我不能提供前preSS-智威汤逊必要的授权头。

The problem is that I can't do the request as I would usually do via AJAX (angular $http.get), as this will not trigger the required file download popup in the browser. Without AJAX though (window.open), I can't provide the necessary authorization header for express-jwt.

我如何能实现从与前preSS和智威汤逊-EX preSS的node.js我的授权文件下载任何暗示?

Any hint on how I can achieve my authorized file download from node.js with express and jwt-express?

推荐答案

一个可能的解决办法是修改服务器端期望像以前一样的头的东西,但在没有这个头的情况下寻找到的参数看到该请求,如果你正在寻找的价值是不存在代替。它不会改变你的previous行为对于其他端点,但它可以让你下载文件与window.open并在URL的参数。您也可以限制这种可能性到端点提供对文件的访问要更加安全。

A possible solution would be to modify your server side to expect something in the header like before, but in case of absence of this header to look into the parameters of the request to see if the value you are looking for is not there instead. It would not change your previous behavior for the other endpoints but it would allow you to download the file with a window.open and a parameter in the url. You can also limit this possibility to the endpoints giving access to files for more security.

这篇关于从前preSS下载文件的Node.js与智威汤逊授权的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆