Rest-auth仍然报告“CSRF cookie未设置”的错误,但是我设置了csrf [英] Rest-auth still reports the error of "CSRF cookie not set", but I've set the csrf

查看:406
本文介绍了Rest-auth仍然报告“CSRF cookie未设置”的错误,但是我设置了csrf的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试使用Django rest-auth包来实现身份验证(登录/注册)功能。

I tried to implement an authentication(login/registration) function using Django rest-auth package.

url(r'^rest-auth/', include('rest_auth.urls')),
url(r'^rest-auth/registration/', include('rest_auth.registration.urls')),

但是当我尝试发布其余的URL时,它给了我错误:

But when I tried to post the rest-auth urls, it gave me the error:

但是,在Nodejs中,我已经使用'csurf'包来设置csrf标记,

However, in Nodejs I've already set the csrf token using the 'csurf' package,

const cookieParser = require('cookie-parser');
const csrf = require('csurf');
const app = new Express();
app.use(cookieParser());
app.use(csrf({ cookie: true }));

此外,我可以看到使用Fiddler的csrf标记:

Also, I can see the csrf token using Fiddler:

你能帮我找出错误在哪里?

Could you help me figure out where is the bug?

推荐答案

请求中的令牌当前命名为 _csrf 。它需要被称为 csrfmiddlewaretoken 为Django提取。

The token in your request is currently named _csrf. It needs to be called csrfmiddlewaretoken for Django to pick it up.

这篇关于Rest-auth仍然报告“CSRF cookie未设置”的错误,但是我设置了csrf的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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