authparams : add the method used to matche the user

git-svn-id: https://svn.fournier38.fr/svn/ProgSVN/trunk@5292 bf3deb0d-5f1a-0410-827f-c0cc1f45334c
This commit is contained in:
2019-05-25 22:46:34 +00:00
parent 3076e88e43
commit e8517ea495

View File

@@ -11,6 +11,8 @@ class authparams
public $email = null; public $email = null;
/** The password of the user when provided */ /** The password of the user when provided */
public $password = null; public $password = null;
/** The method used to get the authentication data */
public $method = null;
/** Parse the different authentication processes to found the email/password /** Parse the different authentication processes to found the email/password
* of the user. * of the user.
@@ -24,6 +26,7 @@ class authparams
{ {
$this->email = "cli"; $this->email = "cli";
$this->password = ""; $this->password = "";
$this->method = null;
} }
else else
{ {
@@ -34,12 +37,14 @@ class authparams
$res = $this->$authprocess(); $res = $this->$authprocess();
$this->email = $res["email"]; $this->email = $res["email"];
$this->password = $res["password"]; $this->password = $res["password"];
$this->method = $authprocess;
break; break;
} }
catch (\Exception $e) catch (\Exception $e)
{ {
$this->email = "anonymous"; $this->email = "anonymous";
$this->password = "anonymous"; $this->password = "anonymous";
$this->method = null;
} }
} }
} }
@@ -63,8 +68,8 @@ class authparams
public function session () public function session ()
// {{{ // {{{
{ {
if (!isset ($_SESSION)) if (!isset ($_SESSION) || session_id () === "")
throw new \Exception ("No session previously opened", 403); session_start ();
if (!isset ($_SESSION["domframework"]["auth"]["email"]) || if (!isset ($_SESSION["domframework"]["auth"]["email"]) ||
!isset ($_SESSION["domframework"]["auth"]["password"])) !isset ($_SESSION["domframework"]["auth"]["password"]))
throw new \Exception ("No previous email in session", 403); throw new \Exception ("No previous email in session", 403);
@@ -78,8 +83,7 @@ class authparams
public function http () public function http ()
// {{{ // {{{
{ {
$realm = dgettext ("domframework", $realm = dgettext ("domframework", "Restricted access");
"Restricted access");
if (!isset ($_SERVER['PHP_AUTH_USER'])) if (!isset ($_SERVER['PHP_AUTH_USER']))
{ {
throw new \Exception ("No user defined in HTTP header", 401); throw new \Exception ("No user defined in HTTP header", 401);
@@ -111,13 +115,13 @@ class authparams
} }
// }}} // }}}
/** Get the information from a JSON Web Token /** Get the information from a Bearer Token
* The token MUST be set in HTTP Header : * The token MUST be set in HTTP Header :
* Authorization: Bearer <token> * Authorization: Bearer <token>
* The real verification are done in authjwt, as we can not have the * The real verification are done in authjwt, as we can not have the
* jwtServerKey defined in property : the execution is done in constructor * jwtServerKey defined in property : the execution is done in constructor
*/ */
public function jwt () public function bearer ()
// {{{ // {{{
{ {
if (! isset ($_SERVER["HTTP_AUTHENTICATION"])) if (! isset ($_SERVER["HTTP_AUTHENTICATION"]))
@@ -125,8 +129,8 @@ class authparams
if (substr ($_SERVER["HTTP_AUTHENTICATION"], 0, 7) !== "Bearer ") if (substr ($_SERVER["HTTP_AUTHENTICATION"], 0, 7) !== "Bearer ")
throw new \Exception ("No Bearer Authentication available", 401); throw new \Exception ("No Bearer Authentication available", 401);
$token = substr ($_SERVER["HTTP_AUTHENTICATION"], 7); $token = substr ($_SERVER["HTTP_AUTHENTICATION"], 7);
return ["email" => "NOT YET VALID : TOKEN IN JWT", return array ("email" => "NOT YET VALID : TOKEN IN JWT",
"password" => "NONE IN JWT"]; "password" => "NONE IN JWT");
} }
// }}} // }}}
} }