<?php
// PHP-JWT library: https://github.com/firebase/php-jwt
include_once "./lib/JWT.php";

$key = "my_shared_key";
$now = time();

$token = array(
    "iat" => $now,
    "sub" => "user@mycompany.com"
//    "aud" => array("sisense"),    // optional: audience array (must contain the value "sisense"
//    "exp" => $now + 1000          // optional: expiration time
);

$jwt = JWT::encode($token, $key);
$hostname = "http://sisense.mycompany.com";
$location = $hostname . "/jwt?jwt=" . $jwt;

if(isset($_GET["return_to"])) {
    $location .= "&return_to=" . urlencode($hostname) . urlencode($_GET["return_to"]);
}

// Redirect
header("Location: " . $location);

?>