zoukankan      html  css  js  c++  java
  • wordpress jwt-auth 多语言 jwt_auth_bad_iss的解决方法

    因为目前处理的 wordpress 网站使用了,使用

    1. qtranslate-x 多语言插件
    2. JWT Authentication for WP REST API 插件 rest api 登录

    调用wp-json/jwt-auth/v1/token 可以登录成功,但通过 jwt.io 网站中的 Debugger,发现 token的 末尾多了 语言后缀 ,如图:

    因为 get_bloginfo('url') 方法获取到的是没有 语言后缀或 默认语言的 wordpress 站点地址(URL)

    只能修改 jwt-authentication-for-wp-rest-api/public/class-jwt-auth-public.phpvalidate_token方法

    $token = JWT::decode($token, $secret_key, array('HS256'));
                /** The Token is decoded now validate the iss */
                if ($token->iss != get_bloginfo('url')) {
                    /** The iss do not match, return error */
                    return new WP_Error(
                        'jwt_auth_bad_iss',
                        __('The iss do not match with this server', 'wp-api-jwt-auth'),
                        array(
                            'status' => 403,
                        )
                    );
                }
                    
    

    修改为

    $token = JWT::decode($token, $secret_key, array('HS256'));
                //get_bloginfo('url')
                $iss_url = defined('JWT_AUTH_ISS_URL') ? JWT_AUTH_ISS_URL : get_bloginfo('url');
                /** The Token is decoded now validate the iss */
                if ($token->iss != $iss_url) {
                    /** The iss do not match, return error */
                    return new WP_Error(
                        'jwt_auth_bad_iss',
                        __('The iss do not match with this server', 'wp-api-jwt-auth'),
                        array(
                            'status' => 403,
                        )
                    );
                }
    

    最后在站点的 wp-config.php 中,添加一个

    // this value equal `WordPress Address (URL)` 
    define('JWT_AUTH_ISS_URL','http://192.168.1.184/test');
    
  • 相关阅读:
    搭建个人Spring-Initializr服务器
    “不蒜子”统计总访问人数脚本
    基于Hazelcast及Kafka实现的分布式锁与集群负载均衡
    虚拟机部署hadoop集群
    程序员、黑客及开发者之间的区别
    今日校园自动登录教程
    逆向DES算法
    来自穷逼对HttpCanary的蹂躏
    今日校园提交签到和查寝-Java实现
    JS 判断数据类型方法
  • 原文地址:https://www.cnblogs.com/fsong/p/10271272.html
Copyright © 2011-2022 走看看