-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
implementing authorization via permissions, policies, roles
- Loading branch information
Showing
25 changed files
with
813 additions
and
140 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<?php | ||
|
||
namespace Fleetbase\Attributes; | ||
|
||
#[\Attribute(\Attribute::TARGET_METHOD)] | ||
class SkipAuthorizationCheck | ||
{ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?php | ||
|
||
namespace Fleetbase\Exceptions; | ||
|
||
use Fleetbase\Support\Auth; | ||
use Illuminate\Http\Request; | ||
|
||
class UnauthorizedRequestException extends \Exception implements \Throwable | ||
{ | ||
protected array $errors = []; | ||
|
||
public function __construct(Request $request, $code = 0, ?\Throwable $previous = null) | ||
{ | ||
$message = $this->getErrorMessage($request); | ||
$this->errors = [$message]; | ||
parent::__construct($message, $code, $previous); | ||
} | ||
|
||
public function getErrorMessage(Request $request): string | ||
{ | ||
$requiredPermission = Auth::getRequiredPermissionNameFromRequest($request); | ||
if (!$requiredPermission) { | ||
return 'Unauthorized Request'; | ||
} | ||
|
||
return 'User is not authorized to ' . $requiredPermission; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.