horus/sentinel
Composer 安装命令:
composer require horus/sentinel
包简介
Pacote de segurança completo para autenticação, autorização e proteção de aplicações.
README 文档
README
Horus Sentinel é um pacote de segurança completo e desacoplado, desenhado para fornecer funcionalidades robustas de autenticação, autorização e proteção para aplicações PHP modernas.
Ele oferece uma forma elegante de gerir:
- ✅ Autenticação de utilizadores
- ✅ Gestão de sessões seguras com backend em Redis
- ✅ Proteção contra CSRF e XSS
- ✅ Rate Limiting para prevenir ataques de força bruta
- ✅ Geração e validação de URLs assinadas para rotas seguras
📦 Instalação
Use o Composer:
composer require horus/sentinel ⚙️ Guia de Uso O Sentinel foi desenhado para ser flexível. Ele depende de interfaces, permitindo que você o integre a qualquer framework ou aplicação, fornecendo suas próprias implementações. 1. Implementar as Interfaces A. UserIdentityInterface Sua classe de modelo User precisa implementar esta interface: <?php namespace App\Models; use Horus\Sentinel\Contracts\UserIdentityInterface; class User implements UserIdentityInterface { public function getId(): int { return $this->id; } public function getPasswordHash(): string { return $this->password; } public function getRoles(): array { return [$this->role ?? 'user']; } } B. UserRepositoryInterface Você precisa criar um repositório que saiba como buscar os utilizadores na base de dados: <?php namespace App\Repositories; use Horus\Sentinel\Contracts\UserRepositoryInterface; use Horus\Sentinel\Contracts\UserIdentityInterface; use App\Models\User; class UserRepository implements UserRepositoryInterface { public function findById(int $id): ?UserIdentityInterface { return User::find($id); } public function findByEmail(string $email): ?UserIdentityInterface { // Ex: return User::where('email', $email)->first(); } } C. RateLimiterInterface (Opcional) Implemente a interface de rate limiting se desejar controlar o número de tentativas de login. 2. Inicializar o Sentinel No bootstrap da sua aplicação (bootstrap/app.php ou equivalente): use Horus\Sentinel\Sentinel; use App\Repositories\UserRepository; use App\Repositories\RedisRateLimiter; $appKey = getenv('APP_KEY'); // Chave secreta do seu .env $sentinel = new Sentinel( new UserRepository(), new RedisRateLimiter(), $appKey ); Se estiver usando um container de injeção de dependência (DI), registre como singleton: $container->singleton(Sentinel::class, fn() => $sentinel); 3. Utilização 🔐 Autenticação php Copiar Editar $email = $_POST['email']; $password = $_POST['password']; if ($sentinel->login($email, $password)) { header('Location: /dashboard'); exit; } 🔒 Proteção de Rotas (Middleware) class AuthMiddleware { public function handle($request, $next) { global $sentinel; if (!$sentinel->user()) { header('Location: /login'); exit; } return $next($request); } } 🛡️ CSRF Protection No formulário: <form method="POST"> <?php echo $sentinel->csrfInput(); ?> <button>Enviar</button> </form> No controlador: if (!$sentinel->validateCsrfToken($_POST['_csrf'] ?? null)) { // Erro 403 } 🔗 URLs Assinadas Gerar o link: $urlSegura = $sentinel->signUrl('http://meusite.com/cancelar-conta', 3600); // válido por 1 hora Validar na rota: if (!$sentinel->validateSignedUrl($urlCompleta)) { // Erro 401 - link inválido ou expirado } ✅ Contribuição Pull Requests são bem-vindos. Para contribuições maiores, abra uma Issue para discutir mudanças antes. 📄 Licença MIT © 2025 [Seu Nome ou Organização]
horus/sentinel 适用场景与选型建议
horus/sentinel 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 51 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 06 月 20 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「php」 「authorization」 「security」 「Authentication」 「auth」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 horus/sentinel 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 horus/sentinel 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 horus/sentinel 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Ory-Hydra OAuth 2.0 Client Provider for The PHP League OAuth2-Client
A lightweight and powerful OAuth 2.0 authorization and resource server library with support for all the core specification grants. This library will allow you to secure your API with OAuth and allow your applications users to approve apps that want to access their data from your API.
Provide a way to secure accesses to all routes of an symfony application.
It's a barebone security class written on PHP
Laravel JWT auth service package
Contao CMS integrity check for some files
统计信息
- 总下载量: 51
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 20
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-06-20