Django 内部 API 客户端/服务器身份验证与否?

Django 内部 API 客户端/服务器身份验证与否?

问题描述:

我有一个 django 项目,在其中我公开了一些 api 端点(api 端点 = 获取/发布的答案,返回 json 响应,如果我的定义有误,请纠正我).我在前端使用这些端点,例如更新计数或获取更新的内容,或无数其他事情.我在服务器端处理表示逻辑,在模板中,在某些情况下,将呈现的字符串模板发送给客户端.

I have a django project, in which i expose a few api endpoints (api endpoint = answers to get/post, returns json response, correct me if im wrong in my definition). Those endpoints are used by me on front end, like update counts or get updated content, or a myriad other things. I handle the representation logic on server side, in templates, and in some cases send a rendered to string template to the client.

这里是我试图回答的问题:

So here are the questions im trying to answer:

  1. 我需要在客户端和服务器之间进行某种身份验证吗?
  2. django 跨源保护是否足够?
  3. 在这张图片中,哪里适合 django-oauth-toolkit 之类的包?还有 django-rest-framework?
  4. 如果我不在客户端和服务器之间添加任何身份验证,我是否会让我的服务器对攻击开放?

此外,服务器到服务器的连接是什么?两台服务器都在我的控制之下.

Furthermore, what goes for server-to-server connection? Both servers under my control.

我强烈推荐使用 django-tastypie 用于服务器到客户端的通信.我在服务器到服务器或服务器到客户端的许多应用程序中都使用过它.这允许您应用 django 安全性以及有关授权过程的更多逻辑.它还提供开箱即用的功能:

I would strongly recommend using django-tastypie for server to client communication. I have used it in numerous applications both server to server or server to client. This allows you to apply the django security as well as some more logic regarding the authorization process. It offers also out of the box:

  • 节流
  • json、xml 等格式的序列化
  • 身份验证(基本、apikey、自定义和其他)
  • 验证
  • 授权
  • 分页
  • 缓存

因此,作为一个总体概述,我建议构建这样一个框架,使您的内部 api 在未来的扩展中更具互操作性且更安全.

So, as an overall overview i would suggest on building on such a framework that would make your internal api more interoperable for future extensions and more secure.

现在具体回答您的问题,如果没有至少一些基本的身份验证/授权,我将永远不会启用任何服务器 API.

To specifically now answer your question, i would never enable any server api without at least some basic authentication/authorization.

希望我能回答您关于如何使用框架解决上述所有问题的问题.

Hopefully i answer your questions on how you can deliver all of your above worries with a framework.

您要求的 django-rest-framework 也非常先进且易于使用,但出于我解释的原因,我更喜欢美味派.

The django-rest-framework that you ask for, is also really advanced and easy to use, but i prefer tastypie for the reasons i explain.

希望能帮到你!