JSON Web Token is now in authentication process

git-svn-id: https://svn.fournier38.fr/svn/ProgSVN/trunk@5288 bf3deb0d-5f1a-0410-827f-c0cc1f45334c
This commit is contained in:
2019-05-24 13:30:22 +00:00
parent 5829288988
commit 18ba0f6b20
3 changed files with 65 additions and 28 deletions

View File

@@ -99,6 +99,20 @@ class authentication
return $this->email;
}*/
/** Setter/Getter for debug
* @param integer|null $debug The debug value to get/set
* @return the actual value or this
*/
public function debug ($debug = null)
// {{{
{
if ($debug === null)
return $this->debug;
$this->debug = intval ($debug);
return $this;
}
// }}}
/** Disconnect the user
* @param string|null $url The url to be redirected after a valid
* logout
@@ -106,6 +120,7 @@ class authentication
public function logout ($url = "")
// {{{
{
// TODO : Foreach authentication methods->logout ();
if (session_id () === "")
session_start ();
if ($this->debug) echo "<pre>LOGOUT\n";
@@ -117,7 +132,7 @@ class authentication
"Logout for '".$param["email"]."'");
$authsession->logout ();
unset ($_SESSION["domframework"]["authentication"]);
if ($this->jwtName !== null)
if ($this->jwtServerKey !== null)
{
// Unset the JSON Web Token as the authentication
if ($this->route->debug)
@@ -149,7 +164,6 @@ class authentication
session_start ();
$auth = new auth ();
$authparams = new authparams (array ("session"));
$authparams->jwtServerKey = $this->jwtServerKey;
if (isset ($_SESSION["domframework"]["authentication"]["message"]))
$message = $_SESSION["domframework"]["authentication"]["message"];
else
@@ -241,16 +255,7 @@ class authentication
if ($this->jwtServerKey !== null)
{
// Set the JSON Web Token as the authentication is valid
require_once ("domframework/jwt.php");
$payloadArray = array();
$payloadArray['nbf'] = gmdate ("Y-m-d H:i:s");
$payloadArray["email"] = $authparams->email;
$jwt = new jwt ();
$token = $jwt->encode ($payloadArray, $this->jwtServerKey,
$this->jwtAlgorithm);
if ($this->route->debug)
echo "<tt>Set the JSON Web Token '$this->jwtName' with value '$token'".
"</tt><br/>\n";
$token = $this->createJwtToken ($authparams->email);
echo "<script>localStorage.setItem('$this->jwtName','$token');".
"</script>\n";
}
@@ -262,6 +267,7 @@ class authentication
// }}}
/** Check all the REST API
* @return array The details provided by the authentication mecanism
*/
public function verifAuthREST ()
// {{{
@@ -270,7 +276,6 @@ class authentication
echo "=== entering verifAuthREST (restMethods=".
print_r ($this->restMethods, true).")\n";
$authparams = new authparams ($this->restMethods);
$authparams->jwtServerKey = $this->jwtServerKey;
$res = array ("email"=>"anonymous", "password"=>"anonymous");
if ($authparams->email !== "anonymous" &&
$authparams->password !== "anonymous")
@@ -290,7 +295,27 @@ class authentication
}
// }}}
/** Return the JSON Web Token
*/
public function createJwtToken ($email)
// {{{
{
if ($this->jwtServerKey !== null)
{
// Set the JSON Web Token as the authentication is valid
require_once ("domframework/jwt.php");
$payloadArray = array();
$payloadArray["email"] = $email;
$jwt = new jwt ();
$token = $jwt->encode ($payloadArray, $this->jwtServerKey,
$this->jwtAlgorithm);
return $token;
}
}
// }}}
/** Check all the others pages of the site
* @return array The details provided by the authentication mecanism
*/
public function verifAuthHTML ()
// {{{
@@ -301,7 +326,6 @@ class authentication
echo "=== entering verifAuthHTML (htmlMethods=".
print_r ($this->htmlMethods, true).")\n";
$authparams = new authparams ($this->htmlMethods);
$authparams->jwtServerKey = $this->jwtServerKey;
// Don't ask to the provider if anonymous is known
if ($authparams->email === "anonymous" || $authparams->email === null)
{