Laravel oauth2未经授权的重定向

时间:2017-02-20 13:21:55

标签: laravel oauth-2.0 laravel-passport

我正在尝试使用laravel和passport实现oath2。但是我已经成功地完成了所有事情。运行。但我面临的问题是当令牌过期或没有令牌时,url会重定向到laravels登录页面。我期待一条未经授权的错误消息,状态代码为401.

oauth2是使用护照实施的。我认为laravels默认auth正在创建问题。

这是我在路线中的代码

Route::group(['middleware' => 'auth:api'], function () {
    Route::get('users', "\App\Http\Controllers\UserController@getUsers");

    Route::post('permission/add', "\App\Http\Controllers\UserController@createPermission");
    Route::get('permissions', "\App\Http\Controllers\UserController@getPermissions");
    Route::get('permission/{param}', "\App\Http\Controllers\UserController@getPermission");

    Route::post('role/add', "\App\Http\Controllers\UserController@createRole");
    Route::get('roles', "\App\Http\Controllers\UserController@getRoles");

    Route::get('user/profile', function () {
        // Uses Auth Middleware
    });
});

My output when unauthorized

我的config / auth.php

'guards' => [
        'web' => [
            'driver' => 'session',
            'provider' => 'users',
        ],

        'api' => [
            'driver' => 'passport',
            'provider' => 'users',
        ],
    ],

0 个答案:

没有答案