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)
|
$permission = APIPermission::where('key_id', $key->id)->where('permission', $request->route()->getName());
|
||||||
->where('permission', $request->route()->getName())
|
|
||||||
->orWhere('permission', '*')
|
// Suport Wildcards
|
||||||
->first();
|
if (starts_with($request->route()->getName(), 'api.user')) {
|
||||||
if (!$permission) {
|
$permission->orWhere('permission', 'api.user.*');
|
||||||
APILogService::log($request, 'You do not have permission to access this resource.');
|
} else if(starts_with($request->route()->getName(), 'api.admin')) {
|
||||||
throw new AccessDeniedHttpException('You do not have permission to access this resource.');
|
$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