简体   繁体   English

令牌认证-Django Rest Framework邮递员

[英]Token Auth - Django Rest Framework Postman

I am fairly new to Django so sorry if this is a silly question: 我是Django的新手,如果这是一个愚蠢的问题,请对不起:

When I try to send the request through postman I receive this 403 error: 当我尝试通过邮递员发送请求时,出现此403错误:

{ "detail": "CSRF Failed: CSRF token missing or incorrect." }

I have also tried adding it to the params section as well in postman, resulting in the same error. 我也尝试过将其添加到邮递员的params部分中,导致相同的错误。

However, when using the curl command, I receive the correct response: 但是,使用curl命令时,我收到正确的响应:

curl -X POST -d "grant_type=convert_token&client_id=r29GLakM6OZ7c4Zg2cwuSXR7M1jiQHIEEMLvtbWA&client_secret=S2xKO81zzYBUTdxM14QiQWb63jnNvPLIcqDTrN9HIYj7t7ldfuCQFWoziWF6h88OgsMUCUNI6HbhIxZQ8ScPFWUWVcJNjaZspbGkDK1j9SsRYJi9uW6DhTr0A9QKvyOZ&backend=facebook&token=EAAY5l4TWgr4BAMjficP4mPKqlbVwVRXI0Xs5GLXSN97sMyKe3muElrkpXRcxJkiZCMzC7tfZBfT4Cci52Pk6Bb2GQm2BARm23tsJoaViOovmvZABlGlJPPZCJ9OecYvfEinUOBaDeBugiDv614yUzOAIfyE0lfZCAX8YAbYyxnlqYYtmS6ywH" http://localhost:8000/api/social/convert-token

What am I doing wrong? 我究竟做错了什么?

Edit: I am using the django-rest-framework-social-oauth2 and following a tutorial online which did not require passing in any other token in the X-CSRFToken header field. 编辑:我正在使用django-rest-framework-social-oauth2并遵循在线教程,该教程不需要在X-CSRFToken标头字段中传递任何其他令牌。

在此处输入图片说明

My problem was a cookie issue with postman. 我的问题是邮递员的cookie问题。 I deleted the cookies off chrome and disabled the interceptor on postman. 我从Chrome删除了Cookie,并在邮递员上禁用了拦截器。 It would store and use the previous sessions CSRF token instead of generating a new one. 它会存储和使用以前的会话CSRF令牌,而不是生成新的令牌。

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

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