Update middleware to handle wildcards correctly.
This commit is contained in:
parent
0f4648b13a
commit
b1a9a59707
1 changed files with 12 additions and 7 deletions
|
@ -93,13 +93,18 @@ class APISecretToken extends Authorization
|
|||
}
|
||||
}
|
||||
|
||||
$permission = APIPermission::where('key_id', $key->id)
|
||||
->where('permission', $request->route()->getName())
|
||||
->orWhere('permission', '*')
|
||||
->first();
|
||||
if (!$permission) {
|
||||
APILogService::log($request, 'You do not have permission to access this resource.');
|
||||
throw new AccessDeniedHttpException('You do not have permission to access this resource.');
|
||||
$permission = APIPermission::where('key_id', $key->id)->where('permission', $request->route()->getName());
|
||||
|
||||
// Suport Wildcards
|
||||
if (starts_with($request->route()->getName(), 'api.user')) {
|
||||
$permission->orWhere('permission', 'api.user.*');
|
||||
} else if(starts_with($request->route()->getName(), 'api.admin')) {
|
||||
$permission->orWhere('permission', 'api.admin.*');
|
||||
}
|
||||
|
||||
if (!$permission->first()) {
|
||||
APILogService::log($request, 'You do not have permission to access this resource. This API Key requires the ' . $request->route()->getName() . ' permission node.');
|
||||
throw new AccessDeniedHttpException('You do not have permission to access this resource. This API Key requires the ' . $request->route()->getName() . ' permission node.');
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue