Laravel基本认证:api 401未经授权
我有一个Laravel 5.5应用程序(不使用Passport),我正在尝试从使用stock基础设施构建的VueJS组件访问Laravel基本认证:api 401未经授权,laravel,vuejs2,Laravel,Vuejs2,我有一个Laravel 5.5应用程序(不使用Passport),我正在尝试从使用stock基础设施构建的VueJS组件访问/api路由。使用我无法获得有效的、经过身份验证的响应。我可以在这里看到正在传递的XSRF令牌: 我的VueJS: methods: { updateSubscription(newChannelId, oldChannelId) { if (oldChannelId < 1 && newChannel
/api
路由。使用我无法获得有效的、经过身份验证的响应。我可以在这里看到正在传递的XSRF令牌:
我的VueJS:
methods: {
updateSubscription(newChannelId, oldChannelId) {
if (oldChannelId < 1 && newChannelId > 0) {
console.log('new subscription', this);
this.$http.post('/api/subscribe', {
'game_id': this.gameId,
'channel_id': newChannelId
}).then(response => {
// success
}, response => {
console.error('Failed to subscribe');
});
我以为拉威尔把XSRF处理得一干二净,我就不会碰到这个问题了。鉴于我的http内核看起来像:
protected $middlewareGroups = [
'web' => [
\App\Http\Middleware\EncryptCookies::class,
\Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class,
\Illuminate\Session\Middleware\StartSession::class,
// \Illuminate\Session\Middleware\AuthenticateSession::class,
\Illuminate\View\Middleware\ShareErrorsFromSession::class,
\App\Http\Middleware\VerifyCsrfToken::class,
\Illuminate\Routing\Middleware\SubstituteBindings::class,
],
'api' => [
'throttle:60,1',
'bindings',
],
];
/**
* The application's route middleware.
*
* These middleware may be assigned to groups or used individually.
*
* @var array
*/
protected $routeMiddleware = [
'auth' => \Illuminate\Auth\Middleware\Authenticate::class,
'auth.basic' => \Illuminate\Auth\Middleware\AuthenticateWithBasicAuth::class,
'bindings' => \Illuminate\Routing\Middleware\SubstituteBindings::class,
'can' => \Illuminate\Auth\Middleware\Authorize::class,
'guest' => \App\Http\Middleware\RedirectIfAuthenticated::class,
'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests::class,
];
我错过了什么?你发现了这个问题吗?我也一样
protected $middlewareGroups = [
'web' => [
\App\Http\Middleware\EncryptCookies::class,
\Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class,
\Illuminate\Session\Middleware\StartSession::class,
// \Illuminate\Session\Middleware\AuthenticateSession::class,
\Illuminate\View\Middleware\ShareErrorsFromSession::class,
\App\Http\Middleware\VerifyCsrfToken::class,
\Illuminate\Routing\Middleware\SubstituteBindings::class,
],
'api' => [
'throttle:60,1',
'bindings',
],
];
/**
* The application's route middleware.
*
* These middleware may be assigned to groups or used individually.
*
* @var array
*/
protected $routeMiddleware = [
'auth' => \Illuminate\Auth\Middleware\Authenticate::class,
'auth.basic' => \Illuminate\Auth\Middleware\AuthenticateWithBasicAuth::class,
'bindings' => \Illuminate\Routing\Middleware\SubstituteBindings::class,
'can' => \Illuminate\Auth\Middleware\Authorize::class,
'guest' => \App\Http\Middleware\RedirectIfAuthenticated::class,
'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests::class,
];