如何使用Django REST框架和React.js前端对用户进行身份验证? [英] How do I authenticate users with Django REST framework and React.js frontend?

查看:169
本文介绍了如何使用Django REST框架和React.js前端对用户进行身份验证?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用django在后端创建一个网站,在前端使用react.js创建一个网站。这将是我第一次在django中使用前端框架。我正在使用django-allauth在后端(facebook / twitter / google)上进行社交身份验证。

I am making a website with django rest in the backend and react.js in the frontend. This will be my first time using a front end framework with django. I am using django-allauth for social auth on the backend (facebook/twitter/google).

用户通过网络会话(使用allauth)登录后第三方提供商(facebook)如何将数据传递到我的应用程序?

Once the user is signed in through a web session (using allauth) via a 3rd party provider (facebook) how do I pass that data to my react app?

我是否抓住了Facebook令牌,对其进行了身份验证,然后生成了oauth2 / jwt令牌并以某种方式存储它?是否有一些样板代码可以节省我的时间。我不想在这里重新发明轮子。

Do I grab the facebook token, authenticate it, then generate an oauth2/jwt token and store that somehow? Is there some boilerplate/code that will save me time on this. I don't want to reinvent the wheel here.

非常感谢!

推荐答案

获得令牌后,可以将其存储在cookie(如果开发IOS应用程序,则可以存储在钥匙串中),而不是将令牌放入请求标头中,然后向服务器发出请求,例如:

After you get the token, you can store it in cookies(or keychain if you developing an IOS app) than put the token in your request header then make a request to your server like:

curl -H "Authorization: bearer your_access_token" -A "ChangeMeClient/0.1 by YourUsername" http://your_server/your_api

这可能有助于授权请求

这篇关于如何使用Django REST框架和React.js前端对用户进行身份验证?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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