基本身份验证同时应用于两个路由组

时间:2018-08-28 00:06:13

标签: routes basic-authentication laravel-5.6

这是我的路由代码的模型:

Route::group([
    'prefix' => 'account',
], function () {
    Route::group([
        'middleware' => 'basicAuth',
    ], function () {
        Route::post('profile', 'Account\AccountController@profile');
    });
});

Route::group(['prefix' => 'browse'], function () {
    Route::post('catalogue', 'Browsing\BrowsingController@catalogue');
});

Kernel.php

<?php
namespace App\Http;

use Illuminate\Foundation\Http\Kernel as HttpKernel;

class Kernel extends HttpKernel
{
    protected $middleware = [
        // Removed code not relevant to problem
    ];

    protected $middlewareGroups = [
        // Removed code not relevant to problem
    ];

    protected $routeMiddleware = [
        'auth' => \Illuminate\Auth\Middleware\Authenticate::class,
        'auth.basic' => \Illuminate\Auth\Middleware\AuthenticateWithBasicAuth::class,
        'bindings' => \Illuminate\Routing\Middleware\SubstituteBindings::class,
        'cache.headers' => \Illuminate\Http\Middleware\SetCacheHeaders::class,
        'can' => \Illuminate\Auth\Middleware\Authorize::class,
        'guest' => \App\Http\Middleware\RedirectIfAuthenticated::class,
        'signed' => \Illuminate\Routing\Middleware\ValidateSignature::class,
        'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests::class,
        'basicAuth' => \App\Http\Middleware\BasicAuth::class
    ];
}

./account/profile./browse/catalogue都仅在提供了基本身份验证用户凭据的情况下起作用,即使仅account中指定了基本身份验证。

如何获取基本身份验证以仅应用于其中一个路由组?

0 个答案:

没有答案