61 lines
2.0 KiB
PHP
61 lines
2.0 KiB
PHP
![]() |
<?php /* ------ exemple de client CAS <20>crit en PHP --------*/
|
|||
|
|
|||
|
//print( "Content-type: text/html\n" );
|
|||
|
//print( "\n" );
|
|||
|
// localisation du serveur CAS
|
|||
|
define('CAS_BASE','http://authen.demo.net');
|
|||
|
|
|||
|
// propre URL
|
|||
|
//$service = 'http://' . $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI'];
|
|||
|
|
|||
|
$service = 'http://' . $_SERVER['SERVER_NAME'] . '/caspied.php';
|
|||
|
|
|||
|
/** Cette simple fonction r<EFBFBD>alise l?authentification CAS.
|
|||
|
* @return le login de l?utilisateur authentifi<EFBFBD>, ou FALSE.
|
|||
|
*/
|
|||
|
function authenticate() {
|
|||
|
global $service ;
|
|||
|
|
|||
|
// r<>cup<75>ration du ticket (retour du serveur CAS)
|
|||
|
if (!isset($_GET['ticket'])) {
|
|||
|
// pas de ticket : on redirige le navigateur web vers le serveur CAS
|
|||
|
header('Location: ' . CAS_BASE . '/cas/login/?service=' . $service);
|
|||
|
exit() ;
|
|||
|
}
|
|||
|
|
|||
|
// un ticket a <20>t<EFBFBD> transmis, on essaie de le valider aupr<70>s du serveur CAS
|
|||
|
$ticket = $_GET['ticket'];
|
|||
|
// $service = $_GET['service'];
|
|||
|
|
|||
|
print( 'service: '.$service.'<br>' );
|
|||
|
print( 'ticket: '.$ticket.'<br>' );
|
|||
|
//$ticket .= '1';
|
|||
|
$fpage = fopen (CAS_BASE . '/cas/serviceValidate?service='
|
|||
|
. preg_replace('/&/','%26',$service) . '&ticket=' . $ticket, 'r');
|
|||
|
if ($fpage) {
|
|||
|
while (!feof ($fpage)) { $page .= fgets ($fpage, 1024); }
|
|||
|
// analyse de la r<>ponse du serveur CAS
|
|||
|
|
|||
|
if (preg_match('|<cas:authenticationSuccess>.*</cas:authenticationSuccess>|mis',$page)) {
|
|||
|
if(preg_match('|<cas:user>(.*)</cas:user>|',$page,$match)){
|
|||
|
return($match[1]);
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
// probl<62>me de validation
|
|||
|
return FALSE;
|
|||
|
}
|
|||
|
|
|||
|
//print( 'je passe ici' );
|
|||
|
$login = authenticate();
|
|||
|
|
|||
|
if ($login == FALSE ) {
|
|||
|
echo 'Requ<71>te non authentifi<66>e (<a href="'.$service.'"><b>Recommencer</b></a>).';
|
|||
|
exit() ;
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
// <20> ce point, l?utilisateur est authentifi<66>
|
|||
|
echo 'Utilisateur connect<63> : ' . $login . '(<a href="' . CAS_BASE . '/cas/logout"><b>d<>connexion</b></a>)';
|
|||
|
?>
|