简体   繁体   English

如何构建安全的前端和后端?

[英]How to build Front-End apart from Back-End with security?

I have some knowledge of Vue and Experience with Django, wanted to know if there's a way to safely create an app with nuxt and django rest framework.我对 Vue 有一些了解,并且有 Django 的经验,想知道是否有一种方法可以安全地使用 nuxt 和 django rest 框架创建应用程序。

I saw that Nuxt is not a server framework and e only works for doing ssr for Vue, so i was wondering how would i do to use it with drf, i thought about using and api key but since the vue app in client-side would have to access the API directly (eg: submitting forms) would be a breach, right?我看到 Nuxt 不是服务器框架,e 只适用于为 Vue 做 ssr,所以我想知道如何将它与 drf 一起使用,我考虑过使用和 api 密钥,但由于客户端的 vue 应用程序会必须直接访问 API(例如:提交表格)会违规,对吧? like, my API cannot be open to everyone and i cannot store api credentials inside vue app.比如,我的 API 不能对所有人开放,我不能在 vue 应用程序中存储 api 凭据。

Is there a way to use Nuxt & Django Rest Framework together?有没有办法一起使用 Nuxt & Django Rest 框架?

I've already answered questions regarding if Nuxt is private and how to make secure calls , reading some of those can be a nice start.我已经回答了有关 Nuxt是否私有以及如何进行安全调用的问题,阅读其中的一些内容可能是一个不错的开始。

Overall, the practice of having such communication is totally common and can be achieved with a JWT. The main points are:总的来说,进行这种通信的做法是完全常见的,可以通过 JWT 实现。要点是:

  • you create an async pair of keys with Django (like SSH does)您使用 Django 创建一对异步密钥(就像 SSH 一样)
  • keep the private key on your Django server将私钥保存在您的 Django 服务器上
  • expose your public key on the Nuxt site在 Nuxt 网站上公开你的公钥
  • force authentication before doing anything sensitive (using a global middleware)在做任何敏感的事情之前强制认证(使用全局中间件)
  • enjoying fully protected communication享受完全受保护的通讯
  • if somebody tries to break the client-side code, he will still not be able to access the most important part (the actual data in your database)如果有人试图破解客户端代码,他仍然无法访问最重要的部分(数据库中的实际数据)

There are plenty of tutorials on the Web on how to achieve a working JWT flow. Web 上有很多关于如何实现工作 JWT 流程的教程。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM