L’exemple suivant génère une page intégrant :
iframeresizer ;
une callback de redirection post soumission du formulaire sur la page elle-même ;
le positionnement de l'URL envoyée par email à la page elle-même.
ne pas utiliser en production
Code
<?php function get_conf() { $config = parse_ini_file("config.ini"); return $config; } function getToken() { $config = get_conf(); $auth_url = $config["auth_url"]; $auth_realm = $config["auth_realm"]; $auth_client_id = $config["auth_client_id"]; $auth_username = $config["auth_username"]; $auth_password = $config["auth_password"]; $curl = curl_init(); curl_setopt($curl, CURLOPT_URL, $auth_url . "/realms/" . $auth_realm . "/protocol/openid-connect/token"); curl_setopt($curl, CURLOPT_POSTFIELDS, "grant_type=password&client_id=" . $auth_client_id . "&username=" . urlencode($auth_username) . "&password=" . urlencode($auth_password)); curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); $response = curl_exec($curl); curl_close($curl); return json_decode($response)->access_token; } function getFormUrl() { $uuid = array_key_exists("uuid", $_GET) ? $_GET["uuid"] : uniqid(); $email = array_key_exists("email", $_GET) ? $_GET["email"] : "nobody@exemple.com"; $token = getToken(); $config = get_conf(); $api_url = $config["api_url"]; $organisation_id = $config["organisation_id"]; $model_id_or_alias = $config["model_id_or_alias"]; $host = isset($_SERVER['HTTP_X_FORWARDED_HOST']) ? $_SERVER['HTTP_X_FORWARDED_HOST'] : $_SERVER['HTTP_HOST']; $port = isset($_SERVER['HTTP_X_FORWARDED_PORT']) ? $_SERVER['HTTP_X_FORWARDED_PORT'] : ""; $proto = isset($_SERVER['HTTPS']) ? "https" : "http"; $proto = isset($_SERVER['HTTP_X_FORWARDED_PROTO']) ? $_SERVER['HTTP_X_FORWARDED_PROTO'] : $proto; $me = $proto . "://" . $host . ($port ? ":" . $port : "") . $_SERVER['DOCUMENT_URI']; $context = [ "userid" => $uuid, "callback" => "?uuid=". $uuid . "&email=". $email, "country" => "FR", "language" => "fr", "optoutEmail" => $email, "receipt" => false, "iframe" => true, "iframeEventsTargetOrigin" => $me, "optoutEmailLink" => $me . "?uuid=" . $uuid . "&email=" . $email, ]; $curl = curl_init(); curl_setopt($curl, CURLOPT_URL, $api_url . "/organisations/" . $organisation_id . "/consents/" . $model_id_or_alias . "/endpoint"); curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($context)); curl_setopt($curl, CURLOPT_HTTPHEADER, array("Authorization: Bearer $token", "Content-Type: application/json")); curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); $response = curl_exec($curl); curl_close($curl); return json_decode($response)->endpoint; } ?> <!DOCTYPE html> <html lang="fr"> <head> <meta charset="utf-8"> <title>Consent iFrame Integration Test</title> </head> <body> <h2 style="text-align: center">Consent iFrame Integration Test</h2> <iframe src="<?php echo getFormUrl() ?>" width="100%" title="Consent iFrame Integration Test" id="consent" name="consent"></iframe> <script type="text/javascript" src="iframeResizer-4.0.4.js"></script> <script type="text/javascript">iFrameResize({log: false});</script> <script type="application/javascript"> window.addEventListener("message", messageListener, false); function messageListener(event) { if (event.data.search(/consent-callback/) >= 0) { const urlback = event.data.replace(/.*consent-callback\/([^"]*).*/, '$1'); window.location.assign(urlback); } } </script> </body> </html>
Build Docker
Décompressez l'archive dans un répertoire, ajustez la configuration dans le fichier config.ini puis lancez la création de l’image via docker build --tag simple-consent-integration-example .
Run Docker
Une fois l’image créée, démarrez le container via docker run simple-consent-integration-example
, puis rendez vous avec un navigateur sur l’IP indiquée dans les logs, par exemple sur http://172.17.0.2 :