如何在Wordpress的AAM插件中使JWT令牌可以刷新?

问题描述 投票:0回答:1

我在Wordpress中使用AAM插件(6.5.2版),以便用JWT令牌从节点服务器连接用户。

使用该插件来验证、验证或撤销令牌没有问题,但我不能刷新它们,因为它们是......不可刷新的。我得到一个错误405 Error: Request failed with status code 405 与。reason: 'JWT token is not refreshable'

但这种可能性似乎是存在的!

下面是一个token claim的例子。

{
  "iat": 1553820141,
  "iss": "https://aamplugin.com",
  "exp": 1573225283,
  "jti": "b69fc282-2af4-4222-8d81-f405fc6acb8e",
  "userId": 1,
  "revocable": true,
  "refreshable": false
}

我只想有一个 refreshable: true.

我想我应该使用过滤器 aam_jwt_claims_filter 但我不知道到底该怎么做... ...

如果你有一些想法...

谢谢!Raphaël。

wordpress jwt token refresh
1个回答
0
投票

对于Wordpress的高级用户来说,它会看起来像基本的。但对于我这个新手来说,这真的不容易。

我在最后添加了以下代码。functions.php 的主题(所以在 httpdocs/wp-includes):

add_filter('aam_jwt_claims_filter', function($claims) {
    $user = get_user_by('ID', $claims['userId']);
    return array_merge($claims, array(
        'refreshable'  => true,
    ));
}, 10, 1);

希望能帮到你!

© www.soinside.com 2019 - 2024. All rights reserved.