Laravel Passport Authroziation错误

时间:2018-04-16 15:40:28

标签: laravel laravel-5 vue.js axios laravel-passport

我有一个适用于Laravel和VueJs的应用程序。我也有一个VK机器人。 Bot和Vue使用相同的API路由。

对于bot我使用带有下一个标题的oauth访问令牌

  

接受:application / json,授权:Bearer my_token_code

机器人运作良好。

对于VueJs,我使用X-CSRF-TOKEN。当我尝试从vue发送请求时出现错误

  

未认证。

我的路线

Route::middleware('auth:api')->group(function(){

    Route::get('/prepare/', 'CompgenApiController@prepareDefault');

    Route::post('/replace/', 'CompgenApiController@replaceImage');

    Route::get('/replaceall/', 'CompgenApiController@replaceAllImages');

    Route::get('/collage/', 'CompgenApiController@collage'); //@todo replace to POST

    Route::get('/generate/', 'CompgenApiController@generate');

    Route::post('/upload/', 'CompgenApiController@userUpload');

    Route::post('/reupload/', 'CompgenApiController@moderationReupload');

    Route::post('/feedback/', 'CompgenApiController@feedback');

});

我的app / Http / Kernel.php

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,
        \Laravel\Passport\Http\Middleware\CreateFreshApiToken::class
    ],

    'api' => [
        'throttle:1000,1',
        'bindings',
    ],
];

我的app.js

window.axios.defaults.headers.common = {
    'X-Requested-With': 'XMLHttpRequest',
    'X-CSRF-TOKEN' : $('meta[name="csrf-token"]').attr('content')
};

1 个答案:

答案 0 :(得分:0)

您是否将护照提供者更改为护照'?在config / auth.php