From 552fa6ab123ae19f437efa6e30ebebf813b3ef6f Mon Sep 17 00:00:00 2001 From: Dominique Fournier Date: Mon, 9 Dec 2019 13:14:22 +0000 Subject: [PATCH] authentication : JWT use now the authJWT library git-svn-id: https://svn.fournier38.fr/svn/ProgSVN/trunk@5815 bf3deb0d-5f1a-0410-827f-c0cc1f45334c --- authentication.php | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/authentication.php b/authentication.php index 1d2e24d..dfbbad4 100644 --- a/authentication.php +++ b/authentication.php @@ -290,25 +290,27 @@ class authentication // }}} /** Return the JSON Web Token - * @param string|array $payload The user email to store in JSON Web Token - * payload. If an array is provided, it will be the payload + * @param string|array $auth The user data to store in JSON Web Token cache. * The $this->authServers["authjwt"]["algorithm"], * $this->authServers["authjwt"]["cipherKey"] and * $this->authServers["authjwt"]["serverKey"] can be set */ - public function createJwtToken ($payload) + public function createJwtToken ($auth) // {{{ { if (isset ($this->authServers["authjwt"]["serverKey"])) { // Set the JSON Web Token as the authentication is valid - require_once ("domframework/jwt.php"); + require_once ("domframework/authjwt.php"); $algorithm = "HS256"; $cipherKey = null; + $cacheDir = "data/jwtCache"; if (isset ($this->authServers["authjwt"]["algorithm"])) $algorithm = $this->authServers["authjwt"]["algorithm"]; if (isset ($this->authServers["authjwt"]["cipherKey"])) $cipherKey = $this->authServers["authjwt"]["cipherKey"]; + if (isset ($this->authServers["authjwt"]["cacheDir"])) + $cacheDir = $this->authServers["authjwt"]["cacheDir"]; $payloadArray = array(); $payloadArray["email"] = $payload; if (is_array ($payload)) @@ -316,10 +318,12 @@ class authentication if (! key_exists ("email", $payloadArray) || $payloadArray["email"] === "anonymous") throw new \Exception ("JWT Must authenticate", 401); - $jwt = new jwt (); - $token = $jwt->encode ($payloadArray, - $this->authServers["authjwt"]["serverKey"], $algorithm, $cipherKey); - return $token; + $authjwt = new authjwt (); + $authjwt->serverKey = $this->authServers["authjwt"]["serverKey"]; + $authjwt->cipherKey = $cipherKey; + $authjwt->algorithm = $algorithm; + $authjwt->cacheDir = $cacheDir; + return $authjwt->createJwtToken ($payloadArray); } } // }}}