Tôi muốn sử dụng HttpOnly
cookie và tôi đặt nó trong Java như sau:HttpOnly cookie không được gửi theo yêu cầu
...
Cookie accessTokenCookie = new Cookie("token", userToken);
accessTokenCookie.setHttpOnly(true);
accessTokenCookie.setSecure(true);
accessTokenCookie.setPath("/");
response.addCookie(accessTokenCookie);
Cookie refreshTokenCookie = new Cookie("refreshToken", refreshToken);
refreshTokenCookie.setHttpOnly(true);
refreshTokenCookie.setSecure(true);
refreshTokenCookie.setPath("/");
response.addCookie(refreshTokenCookie);
...
tôi có các mặt hàng đáp ứng với các tập tin cookie, nhưng khi tôi gửi yêu cầu tôi tiếp theo không có cookie theo yêu cầu. Có lẽ tôi nhớ điều gì đó, nhưng như tôi đã hiểu, các cookie HttpOnly
này phải được trình duyệt gửi lại theo mọi yêu cầu (JavaScript không có quyền truy cập vào các cookie đó) đến đường dẫn được xác định.
Tôi có Headers sau Yêu cầu:
Accept:application/json, text/plain, */*
Accept-Encoding:gzip, deflate, br
Accept-Language:en-US,en;q=0.8,hu;q=0.6,ro;q=0.4,fr;q=0.2,de;q=0.2
Authorization:Basic dXNlcm5hbWU6cGFzc3dvcmQ=
Connection:keep-alive
Content-Length:35
content-type:text/plain
Host:localhost:8080
Origin:http://localhost:4200
Referer:http://localhost:4200/
User-Agent:Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.95 Safari/537.36
X-Requested-With:XMLHttpRequest
và các tiêu đề phản ứng sau:
Access-Control-Allow-Credentials:true
Access-Control-Allow-Origin:http://localhost:4200
Access-Control-Expose-Headers:Access-Control-Allow-Origin, Content-Type, Date, Link, Server, X-Application-Context, X-Total-Count
Cache-Control:no-cache, no-store, max-age=0, must-revalidate
Content-Length:482
Content-Type:application/json;charset=ISO-8859-1
Date:Fri, 03 Feb 2017 13:11:29 GMT
Expires:0
Pragma:no-cache
Set-Cookie:token=eyJhbGciO;Max-Age=10000;path=/;Secure;HttpOnly
Set-Cookie:refreshToken=eyJhb8w;Max-Age=10000;path=/;Secure;HttpOnly
Vary:Origin
Ngoài ra ở phía khách hàng tôi sử dụng withCredentials: true
trong Angular2 và X-Requested-With:XMLHttpRequest
theo yêu cầu của tiêu đề.
Và đó là Tên miền chéo.
Xin chào !! Tôi đã phải đối mặt với một vấn đề tương tự. Khi tôi gỡ bỏ cờ HTTP chỉ sau đó nó hoạt động. Bạn đã tìm thấy bất kỳ công việc nào khác xung quanh? –
Bằng cách xóa cờ an toàn khỏi cookie, hãy giải quyết sự cố –
Cảm ơn rất nhiều !! Nó hoạt động –