簡體   English   中英

SPA AngularJS / Django REST中的非持久性身份驗證cookie

[英]Non persistent Authentication cookie in a SPA AngularJS / Django REST

我已經為這個問題努力了幾個小時:我有一個用Angular編寫的單頁應用程序,它與DjangoREST后端通信。 我正在嘗試通過會話Cookie實現身份驗證功能。 我的看法是:

1 /向任何未登錄的訪客顯示登錄頁面

2 /進行POST以使用憑據進行url /登錄

3 /獲取一個“ sessionid” cookie並寫入用戶已登錄的服務

4 /將訪問者重定向到保留的內容,並使用get&post訪問帶有cookie的內容

登錄端點已設置並且可以使用。 發布帖子時,我收到一個HTTP 200響應,其中包含用戶信息和Set-Cookie,但后續調用中不包含Cookie:

Request URL: ...
Request Method:POST
Status Code:200 OK
Request Headersview source
Accept:application/json, text/plain, */*
Accept-Encoding:gzip,deflate,sdch
Accept-Language:fr-FR,fr;q=0.8,en-US;q=0.6,en;q=0.4
Connection:keep-alive
Content-Length:38
Content-Type:application/x-www-form-urlencoded; charset=UTF-8
Host:devinify1.herokuapp..
Origin:http://mobilevinify.herokuapp...
Referer:http://mobilevinify.herokuapp...
User-Agent:Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/31.0.1650.63 Safari/537.36
Form Dataview sourceview URL encoded
username:felix@vinify.co
password:test
Response Headersview source
Access-Control-Allow-Origin:*
Connection:keep-alive
Content-Length:189
Content-Type:application/json
Date:Sat, 14 Dec 2013 20:45:14 GMT
Server:gunicorn/18.0
Set-Cookie:sessionid=ijz27zy655qn0cwmlnvr66609hsyvdub; expires=Sat, 28-Dec-2013 20:45:14 GMT; Max-Age=1209600; Path=/
Vary:Cookie

我的代碼是對angular-app示例的非常簡單的修改: https : //github.com/FelixLC/MobileWebApp/blob/master/app/scripts/security/security.js

我已經在localhost和heroku上嘗試過這個。 服務器和客戶端位於不同的域,允許使用CORS。 嘗試撥打電話時,我收到Django的錯誤消息

TypeError at /vinibarwines/
int() argument must be a string or a number, not 'AnonymousUser'

我是否應該嘗試獲取此cookie並將其放入angularJS的標題中?

您可以嘗試使用felix@vinify.co&test登錄http://mobilevinify.herokuapp.com/#/login 然后單擊Vinibar,GET請求上出現500內部錯誤

任何幫助,非常感謝Felix

這是我實際進行身份驗證的完整布局。 Django /角度認證 這是一個相當廣泛的答復,我很樂意回答您可能還有的其他問題。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM