orisai / nette-auth
Orisai Auth integration for Nette
Installs: 8 902
Dependents: 2
Suggesters: 0
Security: 0
Stars: 3
Watchers: 1
Forks: 0
Open Issues: 0
Requires
- php: 7.4 - 8.3
- nette/http: ^3.1.5
- orisai/auth: ^1.0.0|^2.0.0
- orisai/exceptions: ^1.0.0
- orisai/nette-di: ^1.0.7
Requires (Dev)
- brianium/paratest: ^6.3.0
- infection/infection: ^0.26.0|^0.27.0|^0.28.0|^0.29.0
- orisai/coding-standard: ^3.0.0
- phpstan/extension-installer: ^1.0.0
- phpstan/phpstan: ^1.0.0
- phpstan/phpstan-deprecation-rules: ^1.0.0
- phpstan/phpstan-nette: ^1.0.0
- phpstan/phpstan-phpunit: ^1.0.0
- phpstan/phpstan-strict-rules: ^1.0.0
- phpunit/phpunit: ^9.5.0
- staabm/annotate-pull-request-from-checkstyle: ^1.7.0
- tracy/tracy: ^2.8.0
README
Nette Auth
Orisai Auth integration for Nette
📄 Check out our documentation.
💸 If you like Orisai, please make a donation. Thank you!
namespace App\Admin\Article\View; use Orisai\Auth\Authentication\Identity; use Orisai\Auth\Authentication\SimpleFirewall; final class ArticleEditController { private SimpleFirewall $firewall; public function __construct(SimpleFirewall $firewall) { $this->firewall = $firewall; } public function run(): void { if (!$this->firewall->isAllowed('administration.entry')) { // Not allowed } $article = /* get article by ID from request */; if (!$this->firewall->isAllowed('article.edit', $article)) { // Not allowed } // Is allowed } } use App\Core\Article\Article; use Orisai\Auth\Authorization\Policy; use Orisai\Auth\Authorization\PolicyContext; /** * @phpstan-implements Policy<Article> */ final class ArticleEditPolicy implements Policy { public static function getPrivilege(): string { return 'article.edit'; } public static function getRequirementsClass(): string { return Article::class; } /** * @param Article $requirements */ public function isAllowed(Identity $identity, object $requirements, PolicyContext $context): bool { $authorizer = $context->getAuthorizer(); return $authorizer->hasPrivilege($identity, self::getPrivilege()) && $requirements->getAuthor()->getId() === $identity->getId(); } }