Page MenuHomec4science

tequila.php
No OneTemporary

File Metadata

Created
Thu, Oct 31, 21:18

tequila.php

<?php
/**
* Tequila authentication
*
* @package auth_tequila
* @copyright 2004-2021 EPFL <https://www.epfl.ch/>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
/*========================================================================
PHP client for Tequila, v. 2.0.4 (Tue Nov 14 10:47:18 CET 2006)
(C) 2004, Lionel Clavien [lionel dot clavien AT epfl dot ch]
This code is released under the GNU GPL v2 terms (see LICENCE file).
Changelog:
0.1.0, 2004-06-27: Creation
0.1.1, 2004-08-29: Changed RSA authentication method to use the new
server certificate in lieu of the server public key
[openssl bug ?]
0.1.2, 2004-09-04: Configuration options put in tequila_config.inc.php
......
2.0.3 : I forgot.
2.0.4 : Fix problem with cookie. Now it is a session cookie.
2.0.5 : Fix ERROR_SESSION_FILE (replace with ERROR_SESSION_FILE_FORMAT).
Fix bug in fetchAttributes().
3.0.0 : Big rewrite.
Fix session time out
use PHP sessions
hide key attribute in urlaccess.
3.0.1 : Fix INFO_PATH & QUERY_STRING test.
3.0.2 : 2011-08-05 : Include comments from Lucien Chaboudez
Define MIN_SESSION_TIMEOUT
Delete cookie with explicit root path
3.0.3 : 2012-04-12 : Patch from Lucien Chaboudez
LoadSession :Check if all the wanted attributes are present
in the $_SESSION.
TODO:
- implement more documented features (allows, ?)
========================================================================*/
// Start output buffering, for the authentication redirection to work...
ob_start();
class TequilaClient {
// maybe move to configuration file?
const TEQUILA_BIN = "/cgi-bin/tequila";
const COOKIE_NAME = "TequilaPHP";
const COOKIE_LIFE = 86400;
const BODY_GLUE = "+";
const LNG_FRENCH = 0;
const LNG_ENGLISH = 1;
const LNG_GERMAN = 2;
private string $serverURL;
private int $timeout;
private string $logoutURL;
private int $language;
private string $applicationURL;
private string $applicationName;
// one time stuff
private array $wantedAttributes;
private array $filters;
private array $authorised;
private array $allowedRequestHosts;
function __construct(string $server, int $timeout, string $applicationName, string $applicationURL = "", int $language = TequilaClient::LNG_ENGLISH) {
$this->serverURL = $server . TequilaClient::TEQUILA_BIN;
$this->timeout = $timeout;
$this->language = $language;
$this->applicationURL = $applicationURL;
$this->applicationName = $applicationName;
// if no application URL was specified, we try to generate it
if (empty($this->applicationURL)) {
$protocol = isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on' ? "https://" : "http://";
$this->applicationURL = $protocol . $_SERVER['SERVER_NAME'] . ":" . $_SERVER['SERVER_PORT'] . $_SERVER['PHP_SELF'];
if (isset($_SERVER['PATH_INFO']))
$this->applicationURL .= $_SERVER['PATH_INFO'];
if (isset($_SERVER['QUERY_STRING']))
$this->applicationURL .= "?" . $_SERVER['QUERY_STRING'];
}
}
public function authenticate(array $wantedAttributes = array(), $filters = "", $authorised = "") : ?bool {
// Step 1: Check if valid session exists
// If yes,
// Step 2: If a session previously existed, restore it
// Step 3: Establish a new session with the server --> /createrequest
$key = $this->createRequest($wantedAttributes, $filters, $authorised);
return true;
}
public function logout() {}
private function createRequest(array $wantedAttributes = array(), $filters = "", $authorised = "") : string {
$body = array();
$body["urlaccess"] = $this->applicationURL;
$body["dontappendkey"] = "1";
$body["language"] = $this->language;
$body["service"] = $this->applicationName;
if (!empty($wantedAttributes))
$body["request"] = implode(TequilaClient::BODY_GLUE, $wantedAttributes);
if (!empty($filters))
$body["require"] = $filters;
if (!empty($authorised))
$body["allows"] = $authorised;
ob_end_clean();
$res = $this->contactServer('createrequest', $body);
// return the key
return substr(trim($res), 4);
}
private function contactServer($type, $fields = array()) {}
}

Event Timeline