[英]Node JS | Heroku | MongoDB Atlas | How do I make sure only my app can access my backend?
I've built my backend using MongoDB Atlas, Express, and Node JS and deployed it to Heroku.我使用 MongoDB Atlas、Express 和 Node JS 构建了我的后端,并将其部署到 Heroku。 Using Postman, the app is operating properly so far (users are getting added and I'm receiving the json web token correctly).使用 Postman,该应用程序目前运行正常(用户正在添加并且我正在正确接收 json 网络令牌)。
But I'm thinking that this might not be correct because it seems like anyone with access to my Heroku URL and routes can easily create a new user, receive the json web token, and basically operate their entire app using my backend.但我认为这可能不正确,因为似乎任何有权访问我的 Heroku URL 和路由的人都可以轻松创建新用户,接收 json 网络令牌,并基本上使用我的后端操作他们的整个应用程序。
My questions are:我的问题是:
You can use Passportjs to protect your routes, passport will be your middleman between person accessing the back-end and your actual back-end.您可以使用Passportjs来保护您的路线,护照将成为访问后端的人和您的实际后端之间的中间人。
You can give access to the routes if a valid JWT is passed ( JWT strategy ) otherwise it will throw 401 (Unauthorized).如果传递了有效的 JWT( JWT 策略),您可以授予对路由的访问权限,否则它将抛出 401(未授权)。
There are 400+ strategies available, I will recommend JWT one because you are already generating JWT.有 400 多种策略可用,我会推荐 JWT 一种,因为您已经在生成 JWT。
Protecting backed is integral part because most of scripts can disable security on front-end leaving apps vulnerable to attacks.保护后台是不可或缺的一部分,因为大多数脚本可以禁用前端的安全性,使应用程序容易受到攻击。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.