So I have a Backend that has a login method to handle our authentication. In this login I set the cookie that contains the username to the root path, so it can accessed by everything.
RequestMapping(method = RequestMethod.GET, value = "/login", headers = "Accept=application/json")
public @ResponseBody HttpServletResponse login(HttpServletRequest request, HttpServletResponse response) {
// toLog(Level.INFO, "Logging user in.");
String referingURL = request.getHeader("referer");
_LOG.debug("Referer: " + referingURL);
try {
String user = "123456789";
user = SecurityUtils.getCurrentUsername();
Cookie userCookie = new Cookie("USERNAME", user);
userCookie.setSecure(true);
userCookie.setDomain(referingURL);
userCookie.setPath("/");
response.addCookie(userCookie);
_LOG.debug("Cookie Path: " + userCookie.getPath());
response.sendRedirect(referingURL);
return response;
} catch (Exception e) {
// toLog(Level.ERROR, "Error logging user in", e);
throw new ResourceNotFoundException(e);
}
}
On the Angular side, I'm using ngCookies for my cookie retrieval and storage. The Angular version is 1.4.6, for reference.
When I use ngCookies, I do a
$cookies.put('USERNAME', ' ', { path: '/', domain: 'https://example.com', secure: true }
But when I login and have a console.log($cookies.getAll()
or a console.log($cookies.get('USERNAME)
I get either an object with a USERNAME with no value, or an undefined, or an empty object.
What am I doing wrong with my ngCookies or where I'm setting that cookie path?
Aucun commentaire:
Enregistrer un commentaire