cakephp 3.8.13 nginx未经授权

问题描述

我正在尝试在CakePHP中实现JWT身份验证。所以我用了admad/cakePHP-jwt-auth。我可以生成令牌,然后在Header的HTTP请求中发回令牌时,它会返回Unauthorized错误。我正在使用devilBox Nginx来托管服务器。所以我用谷歌搜索,发现在xampp的情况下我们必须允许

SetEnvIf Authorization "(.*)" HTTP_AUTHORIZATION=$1
.htaccess文件中的

。所以我将webroot / .htaccess文件修改

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.PHP [L]
    RewriteCond %{HTTP:Authorization} ^(.*)
    RewriteRule .* - [e=HTTP_AUTHORIZATION:%1]
</IfModule>

然后我检查了Nginx配置文件是否允许Authoriztion。认情况下它不存在,所以我修改配置文件

xdomain_request: |
    # Allow cross domain request from these hosts
    if ( $http_origin ~* (__REGEX__) ) {
        add_header "Access-Control-Allow-Origin" "$http_origin";
        add_header 'Access-Control-Allow-Methods' 'GET,POST,OPTIONS';
        add_header 'Access-Control-Allow-Headers' 'Accept,Authorization,DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Content-Range,Range';
        add_header 'Access-Control-Expose-Headers' 'DNT,Range';
        add_header 'Access-Control-Max-Age' 0;
        return 200;
    }

仍然,我收到未经授权的错误

有人可以帮我解决这个问题吗?我正在用邮递员应用程序对此进行测试。谢谢。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)