|
|
@ -10,7 +10,7 @@ class Token {
|
|
|
|
// Need to be in a config file
|
|
|
|
// Need to be in a config file
|
|
|
|
private string $path_to_key="../sym_keyfile.key";
|
|
|
|
private string $path_to_key="../sym_keyfile.key";
|
|
|
|
|
|
|
|
|
|
|
|
function __construct()
|
|
|
|
public function __construct()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
#$file = fopen($this->path_to_key, 'r');
|
|
|
|
#$file = fopen($this->path_to_key, 'r');
|
|
|
|
#$this->key = fread($file, filesize($this->path_to_key));
|
|
|
|
#$this->key = fread($file, filesize($this->path_to_key));
|
|
|
@ -18,7 +18,7 @@ class Token {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Return json containing JWT with uuid and exp
|
|
|
|
// Return json containing JWT with uuid and exp
|
|
|
|
function getNewJsonToken(string $uuid) :array {
|
|
|
|
public function getNewJsonToken(string $uuid) :array {
|
|
|
|
$payload = [
|
|
|
|
$payload = [
|
|
|
|
'uuid' => $uuid,
|
|
|
|
'uuid' => $uuid,
|
|
|
|
'exp' => strtotime("+2month", time())
|
|
|
|
'exp' => strtotime("+2month", time())
|
|
|
@ -28,7 +28,7 @@ class Token {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Verify the JWT authenticity
|
|
|
|
// Verify the JWT authenticity
|
|
|
|
function verifyToken(string $jwt) :bool {
|
|
|
|
public function verifyToken(string $jwt) :bool {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
JWT::decode($jwt, new Key($this->key, 'HS256'));
|
|
|
|
JWT::decode($jwt, new Key($this->key, 'HS256'));
|
|
|
|
} catch (Exception $e) {
|
|
|
|
} catch (Exception $e) {
|
|
|
@ -39,7 +39,7 @@ class Token {
|
|
|
|
|
|
|
|
|
|
|
|
// Get uuid from JWT
|
|
|
|
// Get uuid from JWT
|
|
|
|
// Missing error handling on bad JWT
|
|
|
|
// Missing error handling on bad JWT
|
|
|
|
function getUuidFromToken(string $jwt) :string {
|
|
|
|
public function getUuidFromToken(string $jwt) :string {
|
|
|
|
$decoded = (array) JWT::decode($jwt, new Key($this->key, 'HS256'));
|
|
|
|
$decoded = (array) JWT::decode($jwt, new Key($this->key, 'HS256'));
|
|
|
|
return $decoded['uuid'];
|
|
|
|
return $decoded['uuid'];
|
|
|
|
}
|
|
|
|
}
|
|
|
|