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:
26
authjwt.php
26
authjwt.php
@@ -4,12 +4,23 @@
|
||||
* @author Dominique Fournier <dominique@fournier38.fr>
|
||||
*/
|
||||
|
||||
require_once ("domframework/jwt.php");
|
||||
|
||||
/** User authentication against JSON Web Token */
|
||||
class authjwt extends auth
|
||||
{
|
||||
/** The JSON Web Token Server key if used
|
||||
*/
|
||||
public $jwtServerKey = null;
|
||||
|
||||
/** If the user is valid, return the email in details
|
||||
*/
|
||||
private $email = null;
|
||||
|
||||
/** Save the token
|
||||
*/
|
||||
private $token = null;
|
||||
|
||||
/** No connection to JWT */
|
||||
public function connect ()
|
||||
// {{{
|
||||
@@ -26,20 +37,27 @@ class authjwt extends auth
|
||||
{
|
||||
if (! isset ($_SERVER["HTTP_AUTHENTICATION"]))
|
||||
throw new \Exception ("No Authentication available", 401);
|
||||
if (substr ($_SERVER["HTTP_AUTHENTICATION"], 0, 7) !== "Bearer")
|
||||
if (substr ($_SERVER["HTTP_AUTHENTICATION"], 0, 7) !== "Bearer ")
|
||||
throw new \Exception ("No Bearer Authentication available", 401);
|
||||
$token = substr ($_SERVER["HTTP_AUTHENTICATION"], 7);
|
||||
$jwt = new jwt ();
|
||||
$payload = $jwt->decode ($token, $this->jwtServerKey);
|
||||
if (! key_exists ("email", $payload))
|
||||
return null;
|
||||
// The JWT was tested in authparams. End of process
|
||||
$this->email = $email;
|
||||
$this->email = $payload->email;
|
||||
$this->token = substr ($_SERVER["HTTP_AUTHENTICATION"], 7);
|
||||
}
|
||||
|
||||
/** Return all the parameters recorded for the authenticate user */
|
||||
public function getdetails ()
|
||||
{
|
||||
if ($email === null)
|
||||
if ($this->email === null)
|
||||
return array ("lastname" => "anonymous",
|
||||
"firstname" => "",
|
||||
"email" => "anonymous");
|
||||
return array ("email" => $this->email);
|
||||
return array ("email" => $this->email,
|
||||
"bearer" => $this->token);
|
||||
}
|
||||
|
||||
/** Method to change the password : unavailable in SESSION auth
|
||||
|
||||
Reference in New Issue
Block a user