authentication : JWT use now the authJWT library

git-svn-id: https://svn.fournier38.fr/svn/ProgSVN/trunk@5815 bf3deb0d-5f1a-0410-827f-c0cc1f45334c
This commit is contained in:
2019-12-09 13:14:22 +00:00
parent 1ab8462266
commit 552fa6ab12

View File

@@ -290,25 +290,27 @@ class authentication
// }}} // }}}
/** Return the JSON Web Token /** Return the JSON Web Token
* @param string|array $payload The user email to store in JSON Web Token * @param string|array $auth The user data to store in JSON Web Token cache.
* payload. If an array is provided, it will be the payload
* The $this->authServers["authjwt"]["algorithm"], * The $this->authServers["authjwt"]["algorithm"],
* $this->authServers["authjwt"]["cipherKey"] and * $this->authServers["authjwt"]["cipherKey"] and
* $this->authServers["authjwt"]["serverKey"] can be set * $this->authServers["authjwt"]["serverKey"] can be set
*/ */
public function createJwtToken ($payload) public function createJwtToken ($auth)
// {{{ // {{{
{ {
if (isset ($this->authServers["authjwt"]["serverKey"])) if (isset ($this->authServers["authjwt"]["serverKey"]))
{ {
// Set the JSON Web Token as the authentication is valid // Set the JSON Web Token as the authentication is valid
require_once ("domframework/jwt.php"); require_once ("domframework/authjwt.php");
$algorithm = "HS256"; $algorithm = "HS256";
$cipherKey = null; $cipherKey = null;
$cacheDir = "data/jwtCache";
if (isset ($this->authServers["authjwt"]["algorithm"])) if (isset ($this->authServers["authjwt"]["algorithm"]))
$algorithm = $this->authServers["authjwt"]["algorithm"]; $algorithm = $this->authServers["authjwt"]["algorithm"];
if (isset ($this->authServers["authjwt"]["cipherKey"])) if (isset ($this->authServers["authjwt"]["cipherKey"]))
$cipherKey = $this->authServers["authjwt"]["cipherKey"]; $cipherKey = $this->authServers["authjwt"]["cipherKey"];
if (isset ($this->authServers["authjwt"]["cacheDir"]))
$cacheDir = $this->authServers["authjwt"]["cacheDir"];
$payloadArray = array(); $payloadArray = array();
$payloadArray["email"] = $payload; $payloadArray["email"] = $payload;
if (is_array ($payload)) if (is_array ($payload))
@@ -316,10 +318,12 @@ class authentication
if (! key_exists ("email", $payloadArray) || if (! key_exists ("email", $payloadArray) ||
$payloadArray["email"] === "anonymous") $payloadArray["email"] === "anonymous")
throw new \Exception ("JWT Must authenticate", 401); throw new \Exception ("JWT Must authenticate", 401);
$jwt = new jwt (); $authjwt = new authjwt ();
$token = $jwt->encode ($payloadArray, $authjwt->serverKey = $this->authServers["authjwt"]["serverKey"];
$this->authServers["authjwt"]["serverKey"], $algorithm, $cipherKey); $authjwt->cipherKey = $cipherKey;
return $token; $authjwt->algorithm = $algorithm;
$authjwt->cacheDir = $cacheDir;
return $authjwt->createJwtToken ($payloadArray);
} }
} }
// }}} // }}}