简体   繁体   English

如何使用 Django Rest 管理移动和 web 身份验证并反应/反应本机?

[英]How to manage mobile and web authentication with Django Rest and react/react native?

We are in the process of setting up a project that requires mobile and web app authentication and were wondering if there are any best practices for implementation.我们正在建立一个需要移动和 web 应用程序身份验证的项目,并且想知道是否有任何最佳实施实践。

For the backend we are currently using django rest framework with a knox token authentication and for the web frontend react.js.对于后端,我们目前使用 django rest 框架和knox 令牌身份验证和 web 前端 react.js。 For the future, there will be a mobile app in react native.未来,React Native 中将会有一个移动应用。

We want to set up the authentication now so that it supports the react native mobile app in the future.我们现在想设置身份验证,以便将来支持 React Native 移动应用程序。 However, I have seen that Knox authentication does not work for mobile apps straight forward as it uses csrf token .但是,我已经看到 Knox 身份验证不适用于移动应用程序,因为它使用csrf token

So I'm wondering if there are any best-practices for mobile app and web authentication that specifically feature good documentation, multi-device login and smooth extensibility of login options (fb, google etc) for the current setup drf and react.js/react native.所以我想知道移动应用程序和 web 身份验证是否有任何最佳实践,特别是当前设置 drf 和 react.js/反应原生。

I'm grateful for any guiding hints.我很感激任何指导性的提示。

AWS Cognito seems to be a solution to your problem: AWS Cognito 似乎可以解决您的问题:

Typically, your users get tokens via an external UI provided by amazon (not really customizable) or by calling the Auth API within your React UI.通常,您的用户通过亚马逊提供的外部 UI(不是真正可定制的)或通过在您的 React UI 中调用 Auth API 来获取令牌。

在此处输入图像描述

Cognito sends access_token , id_token and refresh_token to your react app. Cognito 将access_tokenid_tokenrefresh_token发送到您的 React 应用程序。 You need to pass the access_token to your drf backend (similar to knox token authentication) and validate it again via amazon.您需要将 access_token 传递给您的 drf 后端(类似于 knox 令牌身份验证)并通过 amazon 再次验证它。

Check out the official docs for React , check outthis tutorial for django (it helped me a lot.).查看React 的官方文档,查看django 的本教程(它对我帮助很大。)。

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

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