'Response cookie not being set in browser storage
I'm generating a JWT and sending back to the user as a cookie. I see the response cookie in the network, but the brower isn't storing the cookie, which effectively breaks all my authentication/authorization.
w.Header().Add("Access-Control-Allow-Origin", "*")
w.Header().Add("Access-Control-Allow-Credentials", "true")
w.Header().Add("Access-Control-Allow-Headers", "*")
w.Header().Set("Content-Type", "application/json")
http.SetCookie(w, &http.Cookie{
Name: "auth_token",
Value: jwt,
MaxAge: 3600,
Path: "/",
})
json.NewEncoder(w).Encode(fmt.Sprintf("{'result': '%s'}", jwt))
I should mention that I'm running a UI server on port 3000 and web server on port 8080. I assume the mismatched ports on 127.0.0.1
is causing this to fail, however, I don't know a workaround.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|