Set a cookie using nFactor
You can apply the nFactor custom labels and set a cookie as a factor of the authentication flow. Through custom labels, you can use JavaScript to manipulate the login schema.
To set a cookie as a factor, you do not need to display any information to the user, which is performed with a no schema login. Instead, you must interact with the user’s browser to instruct the login schema to store the desired data. A login schema is required to set the cookie when the page is loaded. The cookie is set with a custom label and JavaScript code.
To implement a factor that sets a cookie, create an XML file called cookie.xml to store the schema in the /nsconfig/loginschema/ directory with the following content:
success more-info /nf/auth/doAuthentication.do /nf/auth/doLogoff.do Cancel nsg_cookie nsg_cookie loginBtn none
In this XML;
- The custom label nsg_cookie is used to create the cookie and submit the form, and the form button.
- The RfWebUI_custom is the new Portal theme based on the RfWebUI theme.
Steps to set a cookie using nFactor
Create a portal theme based on the RfWebUI theme.
add vpn portaltheme RfWebUI_custom -basetheme RfWebUI
This command creates a folder for this theme at /var/netscaler/logon/themes/RfWebUI_custom
Edit the file /var/netscaler/logon/themes/RfWebUI_custom/script.js and add the following script:
CTXS.ExtensionAPI。addCustomCredentialHandler ({/ /The name of the credential, must match the type returned by the server getCredentialTypeName: function () { return "nsg_cookie"; }, // Generate HTML for the custom credential getCredentialTypeMarkup: function (requirements) { var div = $(""); $(document).ready(function() { //Set cookie valid for 1000 days var exdays = 1000; var d = new Date(); d.setTime(d.getTime() + (exdays*24*60*60*1000)); var expires = "expires="+ d.toUTCString(); document.cookie = "NSC_COOKIE_NAME=CookieValue;" + expires + ";path=/"; //Submit form document.getElementById('loginBtn').click(); }); return div; } });
This code performs the following:
- Waits for the browser to finish loading the page
- Sets a cookie called NSC_COOKIE_NAME with the value CookieValue, valid for 1000 days
- Auto-submits the form.
The cookie is created and the user does not need to interact with the page.
Create a login schema to bind to the policy label that represents the set cookie factor.
add authentication loginSchema Cookie_LS -authenticationSchema "/nsconfig/loginschema/cookie.xml"
Create a NO_AUTHN authentication policy to bind to the policy label that represents the set cookie factor.
add authentication Policy NO_AUTHN_POL -rule TRUE -action NO_AUTHN
This policy always evaluates as true, moving the user to the next factor or completing the authentication flow.
Bind the portal theme RfWebUI_custom to the Citrix Gateway virtual server or Citrix ADC AAA virtual server.