18 include_once (
'WHAT/Class.Authenticator.php');
25 private $privatelogin =
false;
33 include_once (
'WHAT/Lib.Http.php');
34 $privatekey = static::getTokenId();
37 if ($this->privatelogin ===
false) {
47 $session->register(
'username', $this->
getAuthUser());
56 $headers = apache_request_headers();
58 if (!empty($headers[
"Authorization"])) {
59 $hAuthorization = $headers[
"Authorization"];
60 } elseif (!empty($headers[
"authorization"])) {
61 $hAuthorization = $headers[
"authorization"];
63 if (!empty($hAuthorization)) {
65 if (preg_match(sprintf(
"/%s\\s+(.*)$/", self::openAuthorizationScheme) , $hAuthorization, $reg)) {
66 $tokenId = trim($reg[1]);
75 include_once (
'WHAT/Class.UserToken.php');
76 include_once (
'WHAT/Class.User.php');
78 $token = static::getUserToken($privatekey);
80 error_log(__CLASS__ .
"::" . __FUNCTION__ .
" " . sprintf(
"Token '%s' not found.", $privatekey));
86 if (!is_object(
$user) || !
$user->isAffected()) {
87 error_log(__CLASS__ .
"::" . __FUNCTION__ .
" " . sprintf(
"Could not get user with uid '%s' for token '%s'.", $uid, $privatekey));
91 if (!static::verifyOpenAccess(
$token)) {
92 error_log(__CLASS__ .
"::" . __FUNCTION__ .
" " . sprintf(
"Access deny for user '%s' with token '%s' : context not match.",
$user->login, $privatekey));
97 if (!static::verifyOpenExpire(
$token)) {
98 error_log(__CLASS__ .
"::" . __FUNCTION__ .
" " . sprintf(
"Access deny for user '%s' with token '%s' : token has expired.",
$user->login, $privatekey));
119 $expiredate = $token->expire;
120 if ($expiredate ===
"infinity") {
123 $date = new \DateTime($expiredate);
124 $now = new \DateTime();
126 return $now <= $date;
130 $rawContext = $token->context;
134 if ($token->type && $token->type !==
"CORE") {
138 if ($rawContext === null) {
143 $context = unserialize($rawContext);
144 if (is_array($context)) {
146 foreach ($context as $k => $v) {
159 include_once (
'WHAT/Class.UserToken.php');
163 error_log(__CLASS__ .
"::" . __FUNCTION__ .
" " . sprintf(
"Token '%s' not found.", $privatekey));
167 $this->token =
$token->getValues();
168 if (
$token->expendable ===
't') {
184 header(
"HTTP/1.0 403 Forbidden",
true);
185 print ___(
"Private key identifier is not valid",
"authentOpen");
192 return $this->privatelogin;
206 header(
"HTTP/1.0 401 Authorization Required");
207 print ___(
"Authorization Required",
"authentOpen");
218 $session->register($name,
$value);
219 return $session->read($name);
229 return $session->read($name);
236 if (!$this->auth_session) {
239 $this->auth_session->Set();
if(substr($wsh, 0, 1)!= '/') $args
setSessionVar($name, $value)
static getLoginFromPrivateKey($privatekey)
const openAuthorizationScheme
if(!function_exists('pgettext')) ___($message, $context="")
consumeToken($privatekey)
static verifyOpenExpire(\UserToken $token)
getHttpVars($name, $def="", $scope="all")
static getUserToken($tokenId)
static verifyOpenAccess(\UserToken $token)
if($file) if($subject==""&&$file) if($subject=="") $err