I am working with a Jersey server which returns a cookie in the following way:
return Response.ok()
.cookie(
new NewCookie(
"userAccessToken", userTokenDTO.getToken(), "/", "",
"what is this", 3600, false
)
).build();
When I call the method which returns the cookie, I get the following result in chrome:
I can even see that chrome has recognized my cookie:
But for some reason it isn't set in the cookie tab:
I have tried setting the domain both to false, null, "", creating an entry in the hosts file renaming 127.0.0.1.
return Response.ok()
.cookie(
new NewCookie(
"userAccessToken", userTokenDTO.getToken(), "/", "127.0.0.1",
"what is this", 3600, false)
).build();
Works in IE 11, but still not Chrome nor Firefox...
I have tried multiple time to insert another host name for 127.0.0.1. In this example it is text.myexample.com. It still doesn't work in any other browser than IE11.
return Response.ok()
.cookie(
new NewCookie(
"userAccessToken", userTokenDTO.getToken(), "/", "test.myexample.com",
"what", 7200, false)
).build();
I tried to do the following in the console of Google Chrome:
document.cookie = "userAccessToken=72bebbe0-44fd-45ce-a6e1-accb72201eff;Version=1;Comment=what;Domain=test.myexample.com;Path=/;Max-Age=7200"
Which is the cookie in the header returned by the server in Chrome. That works fine. I have literally no clue what is going on here.
Turns out the problem was related to the fetch library I am using. If you do not include { credentials: "same-origin" }
in the request, the response cookie isn't being set.
For more information, see: https://github.com/github/fetch/issues/386.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With