<!--
    PROXY SAMPLE
    This is only a sample that show how to call proxy to initiate login with an IdP.
    This page can be also the redirect page when we utilize the proxy.
    The login can be performed by a central login page or by calling directly proxy for login with an IdP.
    In production environment you con also implement here the spid access button markup.

    URL to call directly proxy for login with a IdP is formed as follow:
    /proxy-login.php?client_id=<client_id>&action=login&redirect_uri=<redirect_uri>&idp=<idp>&state=<state>

    URL to call proxy logout is formed as follow
    /proxy-logout.php?client_id=<client_id>&action=logout

    <client_id> and <redirect_uri> here is configured during setup
-->

<html>
    <body>
        <p>
			A breve sarai reindirizato al servizio richiesto...
            <?php
			
			$spid_client_id="59xh1P8N4XxbtI";
			$spid_tenant_id="test";
			$spid_environment="devcloud";
			
			echo "<a href='/proxy.php?client_id=$spid_client_id&action=logout'>Esci</a>";
			
				$client = new SoapClient("https://$spid_environment.trisoftservizi.it/SpidWrapperWS/SpidAuthenticationWS?wsdl");
				$postAttributes="";
		
                foreach($_POST as $attribute=>$value) {
                #    echo "<p>" . $attribute . ": <b>" . $value . "</b></p>";
					$postAttributes=$postAttributes.'§'.$attribute.'£'.$value;
                }
				$postAttributes=$postAttributes.'§'.'client_id£'.$spid_client_id.'§'.'tenant_id£'.$spid_tenant_id;
				#echo $postAttributes;
				$result = $client->attivaSpidAuth($postAttributes);
				#echo $result;


				if (empty($result)) {
					echo "Errore autenticazione";
				} else {
					#$link = "<script  type='text/javascript'>window.open('https://$spid_environment.trisoftservizi.it/home/$spid_tenant_id/it/trisoft/cittadino/htmls/PortaleCittadino.htm?SAMLart=$result','_self')</script>";
					
					echo "<script  type='text/javascript'>document.cookie='trisoftdev_SAMLart=$result; path=/ ';</script>";
					$link = "<script  type='text/javascript'>window.open('https://$spid_environment.trisoftservizi.it/home/$spid_tenant_id/it/trisoft/cittadino/htmls/PortaleCittadino.htm','_self')</script>";
					
					echo $link;
					
				}


            ?>
        </p>
        
    </body>
</html>
