Я следовал руководству здесь: https://laravel.com/docs/5.4/passport#consuming-your-api-with-javascript.
Использование аксиомов:
...
mounted: function() {
axios.get('/api/user')
.then(function (response) {
console.log(response)
})
.catch(function (response) {
console.error(response);
});
},
Но ответ всегда не аутентифицируется, я проверяю, присутствует ли cookie laravel_token, и это:
Я работаю на 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'
};