Cookie handling

The cookie mechanism allows the browser to permanently keep the password, eliminating the need to login when the user revisits the application.

How does the cookie mechanism work?

If the user name and password are valid, the REST service program creates a new cookie to be sent to the browser in the HTTP response. An instantaneous redirection is done, this valid cookie is checked by the service (it returns to step 2 of the workflow) and the connection is accepted (step 3a of the workflow). The next time the user starts the application, the SSO service program will check the validity of this cookie. According to the cookie's expiration, the application may start automatically without requiring the user to login again or returning a new login page.

The cookie is set via the HTTP header “Set-Cookie” and requires a name-value pair that can be sent to the browser by a request on the form.
CALL req.setResponseHeader("Set-Cookie", myCookie)
Where myCookie is a string containing a name-value pair, with optional parameters, for example:
LET myCookie = COOKIE_NAME, "=",
               CookieEncrypt(user,pwd,expiredDate,key), "; ",
              "Path=", getCookiePath(path)
Note that the following information should also be set:

Cookie expiration date handling

The date of expiration is usually defined by the cookie attribute “max-age”. It represents a value in seconds relative to the current date and time. For instance, max-age=3600 means that the cookie will expire in 1 hour.

The max-age attribute is not supported by Internet Explorer. The service could use the attribute “expires”, however it requires an absolute GMT hour and Genero currently doesn't handle this format.

To solve this problem, the expiration date is directly included (and encrypted) inside the cookie value.

The cookie structure

To ease the understanding of this example, the cookie has a simple structure:

'name=value;Path=path_value'

How the cookie is handled in the Simple SSO service

The cookie needs to be checked initially by the Simple SSO service (step 2 of the workflow) in order to know if the application can be executed directly or if the end user needs to login again.

There are three options.

Expiration date of the cookie

When the cookie is created, it is handled like this: It can be easily changed by the constants C_EXPIRATION_COOKIE_CHECKED (value in years) and C_EXPIRATION_COOKIE_UNCHECKED (value in seconds) of the SSOUserFunctions.4gl module.