我在使用CakePHP和JWT进行身份验证时遇到了一个奇怪的问题。
我创建了一个测试应用程序,一切都比我创建一个新项目(真正的项目)好,配置一切都等于,但是出了点问题。
当我尝试请求不允许的api时,我正在接收
{
"message": "You are not authorized to access that location.",
"url": "\/api\/advertisements.json",
"code": 401
}<pre class="cake-error"><a href="javascript:void(0);" onclick="document.getElementById('cakeErr57881c28563e8-trace').style.display = (document.getElementById('cakeErr57881c28563e8-trace').style.display == 'none' ? '' : 'none');"><b>Warning</b> (2)</a>: file_put_contents(/home/erick/Projetos/ProjetoX/projetox/6busca/logs/error.log) [<a href='http://php.net/function.file-put-contents'>function.file-put-contents</a>]: failed to open stream: Permissão negada [<b>CORE/src/Log/Engine/FileLog.php</b>, line <b>134</b>]<div id="cakeErr57881c28563e8-trace" class="cake-stack-trace" style="display: none;"><a href="javascript:void(0);" onclick="document.getElementById('cakeErr57881c28563e8-code').style.display = (document.getElementById('cakeErr57881c28563e8-code').style.display == 'none' ? '' : 'none')">Code</a> <a href="javascript:void(0);" onclick="document.getElementById('cakeErr57881c28563e8-context').style.display = (document.getElementById('cakeErr57881c28563e8-context').style.display == 'none' ? '' : 'none')">Context</a><pre id="cakeErr57881c28563e8-code" class="cake-code-dump" style="display: none;"><code><span style="color: #000000"><span style="color: #0000BB"> $mask </span><span style="color: #007700">= </span><span style="color: #0000BB">$this</span><span style="color: #007700">-></span><span style="color: #0000BB">_config</span><span style="color: #007700">[</span><span style="color: #DD0000">'mask'</span><span style="color: #007700">];</span></span></code>
<span class="code-highlight"><code><span style="color: #000000"><span style="color: #0000BB"> </span><span style="color: #007700">if (empty(</span><span style="color: #0000BB">$mask</span><span style="color: #007700">)) {</span></span></code></span>
<code><span style="color: #000000"><span style="color: #0000BB"> </span><span style="color: #007700">return </span><span style="color: #0000BB">file_put_contents</span><span style="color: #007700">(</span><span style="color: #0000BB">$pathname</span><span style="color: #007700">, </span><span style="color: #0000BB">$output</span><span style="color: #007700">, </span><span style="color: #0000BB">FILE_APPEND</span><span style="color: #007700">);</span></span></code></pre><pre id="cakeErr57881c28563e8-context" class="cake-context" style="display: none;">$level = 'error'
$message = '[Cake\Network\Exception\UnauthorizedException] You are not authorized to access that location.
Request URL: /api/advertisements.json
Referer URL: http://localhost:85/
Client IP: 127.0.0.1
Stack Trace:
.... and a long stacktrace
当它应该只返回时:
{
"message": "You are not authorized to access that location.",
"url": "\/api\/advertisements.json",
"code": 401
}
我真的不知道为什么它会返回HTML代码块,而不仅仅是JSON返回。
由于这段HTML代码重定向到登录的方法:
responseError: function (rejection) {
if(rejection.status === 401) {
var stateService = $injector.get('$state');
stateService.go('login');
}
return $q.reject(rejection);
}
不起作用,因为无法序列化响应
SyntaxError: Unexpected token < in JSON at position 126
任何人都有任何想法? (如果需要,我可以添加更多代码)
答案 0 :(得分:0)
解决方案:
我发现了问题。应用程序无权写入error.log。所以它返回了无法将日志写入erro.log文件的错误。
为文件提供正确的权限解决所有问题。