cas.php 1.18 KB
Newer Older
stc's avatar
stc committed
1
2
3
4
5
6
7
8
<?php
include "xmltoarray.php";

class CAS {

	private $server;
  private $protocol;

9
  public function __construct ($server='https://cas.utc.fr/cas/', $protocol='https') {
stc's avatar
stc committed
10
    $this->server = $server;
11
    $this->protocol = $protocol;
stc's avatar
stc committed
12
13
  }

14
	public function authenticate()	{
stc's avatar
stc committed
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
		if (!isset($_GET['ticket']) || empty($_GET['ticket']))
			return -1;

		$data = file_get_contents($this->server.'serviceValidate?service='.$this->protocol.'://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']);
    //'&ticket='.$_GET['ticket'] inutile?
		if (empty($data))
			return -1;

		$parsed = new xmlToArrayParser($data);

		if (!isset($parsed->array['cas:serviceResponse']['cas:authenticationSuccess']))
			return -1;

		return $parsed->array['cas:serviceResponse']['cas:authenticationSuccess'];
	}


32
	public function login() {
stc's avatar
stc committed
33
34
35
		header('Location: '.$this->server.'login?service='.$this->protocol.'://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']);
	}

36
/* UNUSED, TODO
37
	public function logout()	{
stc's avatar
stc committed
38
39
40
		header('Location: '.$this->server.'logout?service='.$this->protocol.'://'.$_SERVER['HTTP_HOST'].dirname($_SERVER['PHP_SELF']));//ou SCRIPT_NAME?
		// On n'utilise pas REQUEST_URI sinon cela déconnecterait à l'infini.
	}
41
*/
stc's avatar
stc committed
42
}