Exemples

Curl

curl --location --request POST 'http://localhost:8082/connect/token'
--header 'Content-Type: application/x-www-form-urlencoded'
--data-urlencode 'client_id=embedded_******'
--data-urlencode 'client_secret=******'
--data-urlencode 'grant_type=client_credentials'
--data-urlencode 'scope=dashboard_read embedded'
--data-urlencode 'dashboard_guid=******'
--data-urlencode 'public=false'
--data-urlencode 'login=alice'
--data-urlencode 'attributes=[{"name":"Region","values":["Alsace", "\"l'Auvergne\""]}]'

PHP

<!doctype html>
<html lang="fr">
<head>
	<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
	<meta charset="utf-8">
	<title>myreport Embedded</title>
</head>
<body>

<?php

function GetToken($IdentityURL, $client_id, $client_secret, $dashboard_guid, $public, $login, $attributes) {
	$url = "http://localhost:8082/connect/token";

	$encoded = array(
		'scope' => 'dashboard_read embedded',
		'grant_type' => 'client_credentials',
		'client_id' => $client_id,
		'client_secret' => $client_secret,
		'dashboard_guid' => $dashboard_guid,
		'public' => $public,
		'login' => $login,
		'attributes' => $attributes
	);

	$ch = curl_init();
	curl_setopt($ch, CURLOPT_URL, $url);
	curl_setopt($ch, CURLOPT_POST, 1);
	curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($encoded));
	curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
	$server_output = curl_exec($ch);
	curl_close($ch);
	//echo $server_output;
	$jsonoutput = json_decode($server_output, true);

	return $jsonoutput['access_token'];
}

?>


<?php

$clientURL = "http://localhost:8080/embedded";
$IdentityURL = "http://localhost:8082/connect/token";

$publicToken = GetToken($IdentityURL, '*******', '*******', '*******', 'true', 'Public', '[]');

$privateTokenAlice = GetToken($IdentityURL, '********', '*******', '********', 'false', 'alice', '[{"name":"Region","values":["Alsace","Auvergne"]}]');



$optionalIFrameParams = "&responsive=true&vertical_stretch=true";

$publicURL = $clientURL . "?access_token=" . $publicToken . $optionalIFrameParams;

$privateURL = $clientURL . "?access_token=" . $privateTokenAlice . $optionalIFrameParams;

?>

<iframe width="1200" height="650" frameborder="0" src="<?php echo $$publicURL; ?>"></iframe>

<iframe width="1200" height="650" frameborder="0" src="<?php echo $privateURL; ?>"></iframe>

</body>
</html>

C#

Lorsque la demande d'access token est réalisée depuis un environnement C# / .NET, il est recommandé d'utiliser la bibliothèqueIdentityModel, accessible via le gestionnaire de paquets NuGet.

L'implémentation est la suivante (exemple issu de la documentation) :

var response = await client.RequestClientCredentialsTokenAsync(new ClientCredentialsTokenRequest { 
    Address = "http://localhost:8082/connect/token",
    GrantType = "grantType",
    ClientId = "clientId",
    ClientSecret = "clientSecret",
    Scope = "scope",
    Parameters = ... });

Si la requête s'est déroulée avec succès, l'access token peut être récupéré ainsi :

var accessToken = response.AccessToken;
ghostghostghostghostghost
loading table of contents...