php - 在 Wordpress/PHP 中保存全局令牌
问题描述
我正在使用Firebase JWT PHP 包生成 JWT 令牌。我到目前为止的代码如下所示:
function kh_generate_jwt () {
$jwt_key = get_field('jwt_key', 'option');
$current_time = time();
$minutes = 3;
$expiration_time = strtotime('+ ' . $minutes . ' minutes', $current_time);
$payload = array(
"iss" => "XXX",
"aud" => "XXX",
"iat" => $current_time,
"nbf" => $current_time,
"exp" => $expiration_time,
"uid" => get_current_user_id()
);
/**
* IMPORTANT:
* You must specify supported algorithms for your application. See
* https://tools.ietf.org/html/draft-ietf-jose-json-web-algorithms-40
* for a list of spec-compliant algorithms.
*/
$jwt = JWT::encode($payload, $jwt_key);
$decoded = JWT::decode($jwt, $jwt_key, array('HS256'));
}
然后应该可以在整个站点中将编码的有效负载$jwt
用作某种全局变量。我听说全局变量不好用,所以我想知道生成这个令牌然后能够在不同情况下在整个页面上使用令牌的最佳解决方案是什么?
令牌的主要用途是将其作为参数附加到某些 iframe URL。因此,重要的是不要为每个 iframe 生成一个新令牌,而是在页面加载时拥有一个可以通过回显它来应用的全局令牌。
解决方案
推荐阅读
- android-studio - Android Studio 的 Fabric 插件未显示分发屏幕
- c - 如何使用 C 线程从头到尾读取文件?
- c - 使用 OpenMP 和 C 的并行化函数
- python - 如何在棋盘上模拟主教运动
- json - 为什么 TFDBatchMove 为值为“03/11/2019”的日期字段引发异常 ELocalTimeInvalid?
- elasticsearch - 将 Elasticsearch 查询字符串转换为 JSON 查询
- c# - 为什么字典不返回正确的键值?
- arduino - 什么是“数组数组”?- 阿杜诺
- python - 通过 SES 发送电子邮件
- javascript - 如何在firebase中获得按键?