level51/silverstripe-jwt-utils
Composer 安装命令:
composer require level51/silverstripe-jwt-utils
包简介
Utilities for dealing with JWT in SilverStripe
README 文档
README
Lean set of helper classes to deal with JWT in SilverStripe setups.
Install
composer require level51/silverstripe-jwt-utils
| Module Version | PHP Version |
|---|---|
| 1.x | >=8 |
| 0.x | <8 |
Example
use Level51\JWTUtils\JWTUtils; use Level51\JWTUtils\JWTUtilsException; class MyTokenController extends Controller { private static $allowed_actions = ['token']; public function token() { try { $payload = JWTUtils::inst()->byBasicAuth($this->request); return json_encode($payload); } catch(JWTUtilsException $e) { return $this->httpError(403, $e->getMessage()); } } }
With correct config and credentials there will be a payload like the following:
{
"token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJtZW1iZXJJZCI6MSwiaXNzIjoiaHR0cDpcL1wvc2lsdmVyZ3JvdW5kLm1lXC8iLCJleHAiOjE1MTgyNzMwMjIsImlhdCI6MTUxNzY2ODIyMiwicmF0IjoxNTE3NjY4MjIyLCJqdGkiOiI0ZjIyMjViNS0wMzE5LTQ3YTMtYWNjMy1jOWJlNDk4MDc1NTIifQ.vQLLzmB7rWkwQDomAuC6Bfm-J0ITsIfFq4wL8UMAAJs",
"member": {
"id": 1,
"email": "js@lvl51.de",
"firstName": "Julian",
"surname": "Scheuchenzuber"
}
}
Config
Make sure to include an environment variable JWT_SECRET and pick a random value.
Level51\JWTUtils\JWTUtils: secret: '`JWT_SECRET`' # Secret for signature. This is mandatory and there is no default value lifetime_in_days: 7 # Term of validity renew_threshold_in_minutes: 60 # Keep JWT for at least 60 minutes
API
static inst(): Get singleton instancebyBasicAuth($request, $includeMemberData: bool = true): array: Creates a new token from Basic Auth member datarenew($token: string): string: Checks if the given token is valid and needs to be renewedcheck($token: string): bool: Checks if token is valid and non-expired
Maintainer
- JZubero js@lvl51.de
level51/silverstripe-jwt-utils 适用场景与选型建议
level51/silverstripe-jwt-utils 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 6.96k 次下载、GitHub Stars 达 2, 最近一次更新时间为 2018 年 02 月 03 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 level51/silverstripe-jwt-utils 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 level51/silverstripe-jwt-utils 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 6.96k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 2
- 点击次数: 15
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2018-02-03