views:

24

answers:

1

I'd like to place a cookie on the client that holds an authentication token. After they log in with their credentials, they can just send the token instead of credentials until the server determines the token has expired.

Below is the constructor for the cookie. I'm using restlets and am unsure about what to set "path" and "domain" to. What are the purpose of these fields? Also, if I set 'secure' to 'true' does that mean it won't transmit the cookie if the connection is not https?

public CookieSetting(int version,
                     String name,
                     String value,
                     String path,
                     String domain,
                     String comment,
                     int maxAge,
                     boolean secure,
                     boolean accessRestricted);

//'secure' - Indicates if cookie should only be transmitted by secure means.
//'accessRestricted' - Indicates whether to restrict cookie access to untrusted parties.
//  Currently this toggles the non-standard but widely supported HttpOnly cookie parameter.
+1  A: 

For example, if you set domain=xyz.com, path=/app and secure=true, browser will send the cookie when calling https://xyz.com/app/...

if secure=true is set, the cookie will not be sent when using http://xyz.com/app URL.

Purush Rudrakshala
So you can set a cookie for a different domain than the one that is creating it, but by default the cookie is created for the current domain by the browser?
DutrowLLC
Yes, that should work. Generally you should be able to setup domain to sub-domains of the current domain. Browser security, in some cases may block setting cookies for other domains.
Purush Rudrakshala