here is the working example. note that this REALLY needs to be included in a PHP cookbook recipe. note its really pretty simple, but i have not worked with PHP enough recently to have figured this out quickly:
<?php
// written by ashu4code
$parmArray = [ 'Parm1' => 'One'
, 'Parm2' => 'Two'
, 'ServerTime' => date('Y-m-d H:i:s')
];
$state = !empty($_GET["state"]) ? $_GET["state"] : null;
// ?? required?? $code = !empty($_GET["code"]) ? $_GET["code"] : null;
require 'vendor/autoload.php';
use Auth0\SDK\Auth0;
define('redirectUrl' , ( $_SERVER['HTTPS'] ? 'https' : 'http' )
. '://'
. $_SERVER['HTTP_HOST']
. $_SERVER['SCRIPT_NAME']
);
$auth0 = new Auth0([
'domain' => 'dev-2a5XXX8.auth0.com',
'client_id' => 'kZvXXXXXXXC',
'client_secret' => '4pXXXXW0',
'redirect_uri' => constant('redirectUrl'),
'scope' => 'openid profile email',
]);
$userInfo = null;
try {
$userInfo = $auth0->getUser();
} catch (Exception $e) {
$auth0->logout();
error_log( 'Line: ' . __LINE__ . ' -- Caught Auth0 exception: ' . $e->getMessage() . ' -- exiting program.' . "\n" );
header('Location: ?logout=1' ) ;
exit;
}
if (!$userInfo) {
// We have no user info
// pass the param in $state variable
$state = http_build_query($parmArray);
$auth0->login($state, null, []);
exit;
} else {
// User is authenticated
$userInfo = $auth0->getUser();
printf( 'Hello %s!', htmlspecialchars( $userInfo['name'] ) );
// display the parameters
$get_string = $state;
echo '<br />Result:<br />';
parse_str($get_string, $get_array);
echo $get_string;
echo '<br />';
print_r($get_array);
echo '<br />';
phpinfo(); // or just look here for the parameters
}