我已經按照這裏的指南:https://laravel.com/docs/5.4/passport#consuming-your-api-with-javascriptLaravel 5.4護照Axios公司始終返回未認證
使用愛可信:
...
mounted: function() {
axios.get('/api/user')
.then(function (response) {
console.log(response)
})
.catch(function (response) {
console.error(response);
});
},
但反應總是未經驗證的,我檢查,看是否有laravel_token cookie的存在它是:
我上的Apache2(搬運工)運行
----更新 -
經調試,其實際上是XSRF令牌多數民衆贊成在這個方法失敗的TokenGuard
:
/**
* Authenticate the incoming request via the token cookie.
*
* @param Request $request
* @return mixed
*/
protected function authenticateViaCookie($request)
{
try {
$token = $this->decodeJwtTokenCookie($request);
} catch (Exception $e) {
return;
}
# This is not passing:
if (! $this->validCsrf($token, $request) ||
time() >= $token['expiry']) {
return;
}
if ($user = $this->provider->retrieveById($token['sub'])) {
return $user->withAccessToken(new TransientToken);
}
}
我在boostrap.js適當的設置:
window.axios = require('axios');
window.axios.defaults.headers.common = {
'X-Requested-With': 'XMLHttpRequest'
};
我有一個類似的問題。看看你是否可能找到答案http://stackoverflow.com/questions/39228194/passport-unauthenticated-laravel-5-3 –
@RikardOlsson更新 –