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
* @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);
}
}
// }}}