public static function from_token($token, $secret) { $vector = explode(".", $token); if (count($vector) == 3) { $js = json_decode(base64_decode($vector[0]), true); $p = $vector[0] . "." . $vector[1]; if ($vector[2] == hash_hmac($js["alg"], $p, $secret)) { $jwt = new JWT(); $jwt->setHeader($js["alg"]); $jwt->setPayload(base64_decode($vector[1])); } } return $jwt; }
public static function gerar_token() { require_once PROJECT_ADDRESS . "/lib/util/JWT.php"; $jwt = new JWT(); $jwt->setHeader(); $jwt->setPayload(UsuarioController::$usuario->getJson("email,codigo")); $jwt->sign(jwt_secret_key()); self::$sessao->setToken($jwt->getToken()); }