OneTrust Cookie Consent With ForgeRock Identity Cloud


Last updated on June 10th, 2021 at 08:37 pm

Managing cookie consent is a common requirement for web applications. Companies like OneTrust have specialized in helping customers easily implement a cookie consent management framework. Embedding a snippet of JavaScript code on a website is all that is required to enable the familiar cookie consent dialog.

ForgeRock Identity Cloud makes it very easy to embed the OneTrust Cookie Consent script snippet and use it in authentication and self-service journeys.

Use the following script to enable OneTrust Cookie Consent in ForgeRock Identity Cloud:

/* Embed Cookie Consent
 *
 * Author: volker.scheuber@forgerock.com
 * 
 * Embed a OneTrust cookie consent JavaScript in a login/registration journey.
 * 
 * This script needs to be parametrized. It will not work properly as is. It
 * requires a valid OneTrust Key.
 * 
 * The Scripted Decision Node needs the following outcomes defined:
 * - true
 */

/*
 * BEGIN SCRIPT CONFIGURATION
 *
 * REPLACE WITH YOUR OWN ONETRUST KEY
 */
var ONETRUST_KEY = "8a84e8cb-e3fa-4d7a-b1af-20179caddabb";
/*
 * END SCRIPT CONFIGURATION
 */

var script = ''.concat(
  	'var js1 = document.createElement("script");\n').concat(
	'js1.type = "text/javascript";\n').concat(
  	'js1.charset = "UTF-8";\n').concat(
	'js1.src = "https://cdn.cookielaw.org/scripttemplates/otSDKStub.js";\n').concat(
	'js1.setAttribute("data-domain-script", "').concat(ONETRUST_KEY).concat('");\n').concat(
	'document.head.appendChild(js1);\n').concat(
  	'var js2 = document.createElement("script");\n').concat(
	'js2.type = "text/javascript";\n').concat(
  	'js2.innerHTML = "function OptanonWrapper() { }";\n').concat(
	'document.head.appendChild(js2);\n')

var output = true;
var fr = JavaImporter(
    org.forgerock.openam.auth.node.api.Action,
    com.sun.identity.authentication.callbacks.ScriptTextOutputCallback
)
if (callbacks.isEmpty()) {
    action = fr.Action.send(
        new fr.ScriptTextOutputCallback(script)
    ).build()
}
else {
  action = fr.Action.goTo(output).build();
}

Use a Scripted Decision Node in any journey where you want the cookie consent dialog to pop-up.

Leave a Reply

Your email address will not be published. Required fields are marked *