Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CSRF error when using rest_framework.authtoken.views.obtain._auth_token

I am calling obtain.auth_token from urls as follows

url(r'^api-token/','rest_framework.authtoken.views.obtain_auth_token')

I get back

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

I am wondering why this happends as I was under the impression django-rest-framework was usualy CSRF exempt

Thanks

like image 838
user155813 Avatar asked Jun 15 '13 01:06

user155813


2 Answers

That view uses a POST. DRF always requires CSRF for session-authenticated POST's.

Sensitive requests like getting an auth token should use POST for just this reason.

like image 172
paulmelnikow Avatar answered Nov 02 '22 21:11

paulmelnikow


I had the exact same issue. Check if you have sign out of the browser.

like image 2
Ryu_hayabusa Avatar answered Nov 02 '22 20:11

Ryu_hayabusa