...
Note |
---|
ne pas utiliser en production |
Contenu de cette documentation :
Table of Contents | ||
---|---|---|
|
Code
L’exemple discuté ici 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.
Note |
---|
ne pas utiliser en production |
...
Déployer depuis le source
Build Docker
Le code source est disponible sur github : https://github.com/fairandsmart/simple-consent-integration-example
commencez par récupérer le code source :
git clone https://github.com/fairandsmart/simple-consent-integration-example.git
;ajustez la configuration dans le fichier config.ini ;
puis lancez la création de l’image via
docker build --tag simple-consent-integration-example
...
.
...
Code
Code Block | ||||
---|---|---|---|---|
| ||||
<?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 :
...
Run Docker
Une fois l’image créée, démarrez le container via docker run simple-consent-integration-example
Déployer depuis l'image docker
L’image est disponible sur dockerhub : https://hub.docker.com/r/fairandsmart/simple-consent-integration-example .
commencez par récupérer l’image :
docker pull fairandsmart/simple-consent-integration-example
;créez un fichier de configuration “ma-configuration.ini” en vous basant sur l’exemple disponible dans le repo github (https://github.com/fairandsmart/simple-consent-integration-example/blob/master/config.ini ) ;
puis démarrez le container :
docker run --mount type=bind,source=$PWD/ma-configuration.ini,target=/var/www/html/my-config.ini -e CONFIG_FILE_PATH="ma-configuration.ini" fairandsmart/simple-consent-integration-example
;
Tester
Une fois le container démarré, rendez vous avec un navigateur sur l’IP indiquée dans les logs, par exemple sur http://172.17.0.2 :
Code Block | ||
---|---|---|
| ||
$ docker run --mount type=bind,source=$PWD/my-config.ini,target=/var/www/html/my-config.ini -e CONFIG_FILE_PATH="my-config.ini" fairandsmart/simple-consent-integration-example
AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 172.17.0.4. Set the 'ServerName' directive globally to suppress this message
AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 172.17.0.4. Set the 'ServerName' directive globally to suppress this message
[Fri Nov 20 17:16:40.178591 2020] [mpm_prefork:notice] [pid 1] AH00163: Apache/2.4.38 (Debian) PHP/7.2.34 configured -- resuming normal operations
[Fri Nov 20 17:16:40.178616 2020] [core:notice] [pid 1] AH00094: Command line: 'apache2 -D FOREGROUND' |
...
Pour aller plus loin
Filter by label (Content by label) | ||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|