$referrer]))); } if ($_GET['p'] === 'callback') { $redirect = []; if (isset($_GET['state'])) { $redirect = json_decode(base64_decode(urldecode($_GET['state'])), true); $state = $_GET['state']; } $token = postRequest($endpoint, 'token', [ 'grant_type' => 'authorization_code', 'client_id' => $clientId, 'client_secret' => $clientSecret, 'redirect_uri' => "https://www.bi-intouch.nl/external_js_new.php?p=callback", //'redirect_uri' => "https://bi-intouch.nl/callback", 'code' => $_GET['code'], 'state' => $state, ]); if (is_array($token) && array_key_exists('access_token', $token)) { setcookie('sso_access_token', $token['access_token'], time() + 7200, '/', '.bi-intouch.nl', true, true); } // The next line should basically never occur, only by submitting same request twice: if (is_array($token) && array_key_exists('error', $token)) { header('Content-Type: application/json'); die(json_encode(array_merge(['status' => 401], $token))); } } if ($_COOKIE['sso_access_token']) { $ch = curl_init(); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 0); curl_setopt($ch, CURLOPT_TIMEOUT, 0); curl_setopt($ch, CURLOPT_URL, sprintf('%s/%s', $endpoint, 'api/1.0/me')); curl_setopt($ch, CURLOPT_HTTPHEADER, [ sprintf('Content-Length: %s', '0'), sprintf('Content-Type: %s', 'application/json'), sprintf('Authorization: %s %s', 'Bearer', $_COOKIE['sso_access_token']), ]); $response = curl_exec($ch); if ($response == false) { throw new \Exception(curl_error($ch), curl_errno($ch)); } curl_close($ch); $response = is_string($response) ? json_decode($response, true) : []; header('Content-Type: text/javascript'); include("js/__jquery.min.js"); die("jQuery('.fl_logged_in').show();jQuery('.fl_not_logged_in').hide();"); } header('Content-type: text/javascript'); die('window.location.href="'. sprintf('%s/%s?%s', $endpoint, 'authorize', http_build_query([ 'client_id' => $clientId, 'redirect_uri' => "https://www.bi-intouch.nl/external_js_new.php?p=callback", //'redirect_uri' => "https://bi-intouch.nl/callback", 'response_type' => 'code', 'scope' => '', 'state' => $state, ])) .'"'); } header('Content-type: text/javascript'); $arr_path = explode("/", __FILE__); $str_username = $arr_path[2]; include "../config/config.$str_username.php"; if (!isset($_REQUEST['new_sso'])) $_REQUEST['new_sso'] = true; echo 'var domain = "' . cfg::STR_DOMAIN . '";'."\n"; echo 'var domain_vda = "' . cfg::STR_DOMAIN_VDA . '";'."\n"; $arr_vars = array( // secure=false is used on VDAs 'secure' => !(isset($_GET['secure' ]) && $_GET['secure' ] == 'false'), // by default a "curl" is added to the page corner, which links to the account page 'page_curl' => !(isset($_GET['no_curl']) && $_GET['no_curl'] == 'true'), // if no_load is set, script will only get the current user ID (uid variable) 'load' => !(isset($_GET['no_load']) && $_GET['no_load'] == 'true'), // when secure=false, use SSO (POC home page) instead of Pharbase ID instead 'sso' => (isset($_GET['sso']) && $_GET['sso'] == 'true'), // allow POH logins 'poh' => (isset($_GET['poh']) && $_GET['poh'] == 'true'), // Show tabbed new SSO 'bln_tabbed_sso' => (isset($_GET['bln_tabbed_sso']) && $_GET['bln_tabbed_sso'] == 'true'), //the selected tab by default 'int_selected_tab' => (isset($_GET['int_selected_tab']) && $_GET['int_selected_tab'] >0) ? $_GET['int_selected_tab'] : null, //if set, which tabs are shown 'arr_available_tabs' => isset($_GET['arr_available_tabs']) ? $_GET['arr_available_tabs'] : null, //which patient login to show 'str_patient_login' => isset($_GET['str_patient_login']) ? $_GET['str_patient_login'] : null, // disallow users which have use_professional_group_code different to 01, 17, 18 'shield' => (isset($_GET['shield']) && $_GET['shield'] == 'true'), //str_branding_code 'str_branding_code' => isset($_GET['str_branding_code']) ? $_GET['str_branding_code'] : null, //if set to false, dont load jquery 'bln_jquery' => isset($_GET['bln_jquery']) ? $_GET['bln_jquery'] : true, //if set use mobile version 'bln_mobile' => isset($_GET['bln_mobile']) ? $_GET['bln_mobile'] : false, //if set to true, the sso returns with the h= and u= tokens 'bln_token' => isset($_GET['bln_token']) ? $_GET['bln_token'] : false, //if set to true it is a shop landing page 'bln_landing_page' => isset($_GET['bln_landing_page']) ? $_GET['bln_landing_page'] : false, //if set to true show container after login 'bln_show_container' => isset($_GET['bln_show_container']) ? $_GET['bln_show_container'] : false, //if set, this additional parameter is added to the FL_loggedin div on a landing page 'str_extra_parameter' => isset($_GET['str_extra_parameter']) ? urlencode($_GET['str_extra_parameter']) : '', // new session system to allow a maintainable session. 'session_key' => ((isset($_GET['session_key']) && strlen($_GET['session_key'] > 0)) ? $_GET['session_key'] : false), //magic var, set to true on site level if the site uses u/h sync '_sso_common_login' => false ); foreach ($arr_vars as $str_name=>$mix_value) echo "var $str_name = '".$mix_value."';\n"; ?> //