jasny / auth
Slim 框架和其他 PHP 微型框架的认证、授权和访问控制
v2.2.1
2024-08-30 14:18 UTC
Requires
- php: >=8.2.0
- improved/iterable: ^0.1.4
- jasny/immutable: ^2.1
- psr/clock: ^1.0
- psr/event-dispatcher: ^1.0
- psr/http-factory: ^1.0
- psr/http-message: ^1.1
- psr/http-server-middleware: ^1.0
- psr/log: ^1.1
Requires (Dev)
- ext-bcmath: *
- hashids/hashids: ^4.1 | ^5.0
- jasny/phpunit-extension: ^0.5.1
- lcobucci/clock: ^3.2
- lcobucci/jwt: ^4.0 | ^5.0
- phpstan/phpstan: ^1.12.0
- phpunit/phpunit: ^11.3
- squizlabs/php_codesniffer: ^3.10
Conflicts
- hashids/hashids: < 4.1
- lcobucci/jwt: < 4.0
- dev-master
- v2.x-dev
- v2.2.1
- v2.2.0
- v2.1.0
- v2.0.1
- v2.0.0
- v2.0.0-beta7
- v2.0.0-beta6
- v2.0.0-beta5
- v2.0.0-beta4
- v2.0.0-beta3
- v2.0.0-beta2
- v2.0.0-beta1
- v1.0.1
- v1.0.0
- v1.0.0-beta9
- v1.0.0-beta8
- v1.0.0-beta7
- v1.0.0-beta6
- v1.0.0-beta5
- v1.0.0-beta4
- v1.0.0-beta3
- v1.0.0-beta2
- v1.0.0-beta1
- dev-user-class
- dev-token_confirmation
- dev-jwt
- dev-hmac
This package is auto-updated.
Last update: 2024-09-03 20:46:45 UTC
README
Jasny Auth
为 Slim 框架 和其他 PHP 微型框架提供认证、授权和访问控制。
特性
- 多种授权策略,如分组(用于 acl)和级别。
- 授权上下文(例如:“用户是否是此团队的管理员?”)。
- 登录和注销的 PSR-14 事件。
- 用于访问控制的 PSR-15 中间件。
- 会话失效,显式或隐式(例如,在更改密码后)。
- 支持多因素认证。
- 支持 JWT 和 Bearer 认证。
- 注册确认和忘记密码的确认令牌。
- 对有趣事件的 PSR-3 记录。
- 可自定义以满足您应用程序的需求。
安装
使用 composer 安装
composer require jasny/auth
用法
Auth
是一个组合类。它接受一个 authz、storage,以及可选的 confirmation 服务。
use Jasny\Auth\Auth; use Jasny\Auth\Authz\Levels; $levels = new Levels(['user' => 1, 'moderator' => 10, 'admin' => 100]); $auth = new Auth($levels, new AuthStorage()); session_start(); $auth->initialize(); // Later... if (!$auth->is('admin')) { http_response_code(403); echo "Access denied"; exit(); }
Auth
服务在初始化之前是不可用的。这应该在会话启动后完成。
session_start(); $auth->initialize();