Les modèles de consentement peuvent être intégrés comme iframe à tout site HTML, de manière à réaliser un intégration sans couture.
les snippets sont volontairement gardés au plus simple (pas de contrôle d’erreur, de gestion des sessions etc … ).
Cinématique
Une fois l’intégration réalisée, la cinématique se déroule ainsi :
...
Exemple en PHP :
Code Block | ||||
---|---|---|---|---|
| ||||
function getToken() { $auth_url = "https://auth.fairandsmart.com/auth"; $auth_client_id = "fsorg"; $auth_username = "mysecretidentity@example.com"; $auth_password = "MySecretPassword"; $token = ""; $curl = curl_init(); curl_setopt_array($curl, array( CURLOPT_URL =>, $auth_url . "/realms/FairAndSmart" . $auth_realm . "/protocol/openid-connect/token",); CURLOPT_RETURNTRANSFER => true, CURLOPT_ENCODING => "", CURLOPT_MAXREDIRS => 10, CURLOPT_TIMEOUT => 30, CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, CURLOPT_CUSTOMREQUEST => "POST", CURLOPT_POSTFIELDS => curl_setopt($curl, CURLOPT_POSTFIELDS, "grant_type=password&client_id=" . $auth_client_id . "&username=" . urlencode($auth_username) . "&password=" . urlencode($auth_password,)); CURLOPT_HTTPHEADER => array( "Content-Type: application/x-www-form-urlencoded", "cache-control: no-cache", ), )); curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); $response = curl_exec($curl); $err = curl_error($curl); curl_close($curl); if ($err) { echo "cURL Error #:" . $err; } else { $token = return json_decode($response)->access_token; } return $token; } |
À l’issue de ce snippet, la variable token
contiendra le token d’authentification..
...
Il est nécessaire d’indiquer un identifiant qui permettra de relayer le formulaire à son utilisateur (userid
ci-dessous).
Code Block | ||||
---|---|---|---|---|
| ||||
function getFormUrl($token) { $api_url = "https://core.fairandsmart.com/api"; $organisation_id = "XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX"; $model_id_or_alias = "YYYYYYYY-YYYY-YYYY-YYYY-YYYYYYYYYYYY"; $context $host = $_SERVER['HTTP_HOST']; $port = ""; $proto = "userid" => "test fns", isset($_SERVER['HTTPS']) ? "https" : "http"; $context = [ "userid" => $uuid, "callback" => "https://www.fairandsmart.com", "?uuid=". $uuid . "&email=". $email . "&receipt=". $receipt . "&stage=2", // "country" => "FR", "language" => "fr", "optoutEmail" => $email != // "optoutEmail" => ? $email . "foo@bar@fairandsmart.com", : null, // "receipt" => true$receipt, "iframe" => true, "iframeEventsTargetOrigin" => $proto . "http://localhost:8080"" . $host . ($port ? ":" . $port : ""), ]; $curl = curl_init(); curl_setopt_array($curl, array( CURLOPT_URL =>, $api_url . "/organisations/" . $organisation_id . "/consents/" . $model_id_or_alias . "/endpoint",); CURLOPT_RETURNTRANSFER => true, CURLOPT_ENCODING => "", CURLOPT_MAXREDIRS => 10, CURLOPT_TIMEOUT => 30, CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, CURLOPT_CUSTOMREQUEST => "POST", CURLOPT_POSTFIELDS => curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($context)),; curl_setopt($curl, CURLOPT_HTTPHEADER =>, array( "Authorization: Bearer $token", "Content-Type: application/json", ), )); $response = curl_execsetopt($curl, CURLOPT_RETURNTRANSFER, true); $err$response = curl_errorexec($curl); curl_close($curl); if ($err) { echo "cURL Error #:" . $err; } else { $url = json_decode($response)->endpoint; } return $url; } |
À la fin de ce snippet, la variable $url
contient l’url du formulaire de consentement.
...
Par exemple dans le cas d’une iframe :
Code Block | ||||
---|---|---|---|---|
| ||||
<html> <body> <iframe width="700" height="500" src="<?php echo getForm(getToken()) ?>"></iframe> </body> </html> |
...
Note |
---|
dans ce cas l’appel HTTP de génération de l’URL du formulaire doit contenir le paramètre “iframe” positionné à “true”. |
Code Block | ||
---|---|---|
| ||
<html> <body> <style>iframe { width: 1px; min-width: 100%; }</style> <script src="http://url-du-script/iframeResizer.min.js"/> <script>iFrameResize({ log: true }, '#myIframe');</script> <iframe id="myIframe" src="<?php echo getFormgetFormUrl(getToken()) ?>" width="100%" title="Consent iFrame" id="consent"></iframe> </body> </html> |
...
Note |
---|
dans ce cas l’appel HTTP de génération de l’URL du formulaire doit contenir le paramètre |
Code Block | ||||
---|---|---|---|---|
| ||||
<html> <body> <script type="application/javascript"> window.addEventListener("message", messageListener, false); function messageListener(event) { console.log(event); if (event.data.startsWithsearch('/consent-callback/') >= 0) { const urlback = event.data.replace('/.*consent-callback/'\/([^"]*).*/, '$1'); window.location.assign(urlback); } } </script> <iframe width="700" height="500" src="<?php echo getFormgetFormUrl(getToken()) ?>" width="100%" title="Consent iFrame" id="consent"></iframe> </body> </html> |
...