Skip to content

Multiple Guards on a Single Route #488

@derekrprice

Description

@derekrprice
  • Laravel Version: 6.8
  • Laratrust Version: 5.2.9

Describe the bug
Laravel handles this auth statement just fine, such that 3 user types, each with their own guards can share a single route. If any of the three guards allow access, then access to the route is allowed:

Route::middleware([
    'auth:api,client,its'
])->group(function () {
    Route::get('/stuff', 'StuffController@all');
});

Unfortunately, when I try to add a Laratrust permission check, only the first guard that I list is checked:

Route::middleware([
    'auth:api,client,its',
    'permission:read-asset,guard:api|guard:client|guard:its'
])->group(function () {
    Route::get('/stuff', 'StuffController@all');
});

This seems to be an explicit assumption of LaratrustMiddleware::extractGuard(), as it uses ->first() during the extraction:

protected function extractGuard($string)
{
    $options = Collection::make(explode('|', $string));

    return $options->reject(function ($option) {
        return strpos($option, 'guard:') === false;
    })->map(function ($option) {
        return explode(':', $option)[1];
    })->first();
}

To Reproduce
See above.

Question
Is there some way to manage multiple guards on the same route?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions