Skip to content

Commit 2f1abba

Browse files
committed
Changed filters to accept any amount of parameters
1 parent 2a96807 commit 2f1abba

File tree

3 files changed

+17
-14
lines changed

3 files changed

+17
-14
lines changed

src/LucaDegasperi/OAuth2Server/Filters/CheckAuthorizationParamsFilter.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,9 @@ class CheckAuthorizationParamsFilter
1414
*
1515
* @param Route $route the route being called
1616
* @param Request $request the request object
17-
* @param string $scope additional filter arguments
1817
* @return Response|null a bad response in case the params are invalid
1918
*/
20-
public function filter($route, $request, $scope = null)
19+
public function filter($route, $request)
2120
{
2221
try {
2322

src/LucaDegasperi/OAuth2Server/Filters/OAuthFilter.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class OAuthFilter
1515
* @param string $scope additional filter arguments
1616
* @return Response|null a bad response in case the request is invalid
1717
*/
18-
public function filter($route, $request, $scope = null)
18+
public function filter()
1919
{
2020
try {
2121
ResourceServer::isValid(Config::get('lucadegasperi/oauth2-server-laravel::oauth2.http_headers_only'));
@@ -26,9 +26,10 @@ public function filter($route, $request, $scope = null)
2626
'error_message' => $e->getMessage(),
2727
), 403);
2828
}
29-
30-
if (! is_null($scope)) {
31-
$scopes = explode(',', $scope);
29+
30+
if (func_num_args() > 2) {
31+
$args = func_get_args();
32+
$scopes = array_slice($args, 2);
3233

3334
foreach ($scopes as $s) {
3435
if (! ResourceServer::hasScope($s)) {

src/LucaDegasperi/OAuth2Server/Filters/OAuthOwnerFilter.php

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,17 @@ class OAuthOwnerFilter
1313
* @param string $scope the allowed owners (comma separated)
1414
* @return Response|null a bad response in case the owner is not authorized
1515
*/
16-
public function filter($route, $request, $scope = null)
17-
{
18-
if (! is_null($scope) and ResourceServer::getOwnerType() !== $scope) {
19-
return Response::json(array(
20-
'status' => 403,
21-
'error' => 'forbidden',
22-
'error_message' => 'Only access tokens representing '.$scope.' can use this endpoint',
23-
), 403);
16+
public function filter()
17+
{
18+
if (func_num_args() > 2) {
19+
$owner_types = array_slice(func_get_args(), 2);
20+
if(!in_array(ResourceServer::getOwnerType(), $owner_types)) {
21+
return Response::json(array(
22+
'status' => 403,
23+
'error' => 'forbidden',
24+
'error_message' => 'Only access tokens representing ' . implode(',', $owner_types) . ' can use this endpoint',
25+
), 403);
26+
}
2427
}
2528
}
2629
}

0 commit comments

Comments
 (0)