2016-07-14 9 views
0

Ich habe ein seltsames Problem mit der Authentifizierung mit CakePHP und der JWT konfrontiert.Authentifizierung seltsames Verhalten mit JWT, CakePHP 3 und AngularJS

Ich habe eine Testanwendung erstellt und alles funktioniert gut, als ich ein neues Projekt erstellt (das echte Projekt), konfigurieren Sie alles gleich, aber etwas ist falsch.

Wenn ich versuche, eine nicht gestattet api zu beantragen, Ich erhalte

{ 
    "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">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$mask&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">$this</span><span style="color: #007700">-&gt;</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">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #007700">if&nbsp;(empty(</span><span style="color: #0000BB">$mask</span><span style="color: #007700">))&nbsp;{</span></span></code></span> 
<code><span style="color: #000000"><span style="color: #0000BB">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #007700">return&nbsp;</span><span style="color: #0000BB">file_put_contents</span><span style="color: #007700">(</span><span style="color: #0000BB">$pathname</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$output</span><span style="color: #007700">,&nbsp;</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 = &#039;error&#039; 
$message = &#039;[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 

Wenn es nur zurück angenommen hat:

{ 
    "message": "You are not authorized to access that location.", 
    "url": "\/api\/advertisements.json", 
    "code": 401 
} 

Ich weiß wirklich nicht, warum es das zurückkehrt Block von HTML-Code und nicht nur die JSON-Rückkehr.

Aufgrund dieses Stück HTML-Code der Methode zur Login umleiten:

responseError: function (rejection) { 
    if(rejection.status === 401) { 
     var stateService = $injector.get('$state'); 
     stateService.go('login'); 
    } 
    return $q.reject(rejection); 
} 

funktioniert nicht, weil nicht die Antwort serialisiert

SyntaxError: Unexpected token < in JSON at position 126 

jemand eine Idee? (Kann ich mehr Teile des Codes setzen, wenn erforderlich)

Antwort

0

Lösung:

Ich finde das Problem. Die Anwendung hatte keine Berechtigung, in die error.log zu schreiben. Daher wurde der Fehler zurückgegeben, der das Protokoll nicht in die Datei erro.log schreiben konnte.

Geben Sie die richtigen Berechtigungen für die Datei lösen Sie alles.