Custom Auth
You can override the following methods of Tina4\Auth, getToken & validToken
use Nowakowskir\JWT\JWT;
class MyAuth extends \Tina4\Auth
{
public function getToken(array $payLoad = [], string $privateKey = "", string $encryption = JWT::ALGORITHM_RS256): string
{
//replace with your own code or use the defaults
return parent::getToken($payLoad, $privateKey, $encryption);
}
public function validToken(string $token, string $publicKey = "", string $encryption = JWT::ALGORITHM_RS256): bool
{
if ($token === $_ENV["SOME_API_KEY"]) { //from .env file
return true;
} else {
return parent::validToken($token, $publicKey, $encryption);
}
}
}
And then finally you can do some testing :
$payload = ["email" => "tina4@test.com", "name" => "Tina4"];
$token = (new MyAuth())->getToken($payload);
echo $token;
$myAuth = (new MyAuth());
if ($myAuth->validToken($token)) {
$parseToken = $myAuth->getPayLoad($token);
} else {
$parseToken = ["error" => "Invalid or expired"];
}
print_r ($parseToken);