lgrevelink/laravel-simple-jwt
Composer 安装命令:
composer require lgrevelink/laravel-simple-jwt
包简介
Utilties for using the php-simple-jwt package in Laravel/Lumen projects.
README 文档
README
Laravel and Lumen utilities to kickstart the usage of the PHP Simple JWT package.
Supported functionalities;
- Artisan make command for JWT Blueprints (
make:jwt-blueprint) - Validator rule for JWT validation
Installation
composer require lgrevelink/laravel-simple-jwt
For Laravel
Laravel's auto-discovery directly registers the service provider so it should be instantly usable. If you don't use auto-discovery, please add the SimpleJwtServiceProvider to the provider array in config/app.php.
LGrevelink\LaravelSimpleJWT\Providers\SimpleJwtServiceProvider::class
Both the artisan command and the validator are directly registered by adding the service provider.
For Lumen
Using this package in lumen requires you to register the service provider in bootstrap/app.php.
$app->register(LGrevelink\LaravelSimpleJWT\Providers\SimpleJwtServiceProvider::class);
Auto-extending the validator rule only works when the Facades have been setup. This can be done by enabling the withFacades option in bootstrap/app.php. Aliases are not necessary.
$app->withFacades();
Usage
Generator command
After getting set up, generating your first Blueprint is very easy.
php artisan make:jwt-blueprint MyFirstBlueprint
A series of questions are following setting up the default claims supported by JWT. Values you don't want to use can be left empty and won't be added. The default namespace where the blueprints will be placed is App\JwtTokens.
All date-related claims (e.g. expiration time) are treated as relative values from the moment generation. Find more information about the Simple JWT package and its usage here.
Validator
There are 2 general ways of using the validator rule.
Basic usage
$request->validate([ 'foo' => 'jwt', 'bar' => new ValidJwt(), ]);
This only validates whether the token has a valid JWT structure.
Blueprint usage
$request->validate([ 'foo' => 'jwt:' . App\JwtTokens\MyFirstBlueprint::class, 'bar' => new ValidJwt(App\JwtTokens\MyFirstBlueprint::class), ]);
This validates the token directly against the given blueprint.
Tests
Tests are written with PHPUnit and can be run via the following composer command;
composer run test
lgrevelink/laravel-simple-jwt 适用场景与选型建议
lgrevelink/laravel-simple-jwt 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1.82k 次下载、GitHub Stars 达 1, 最近一次更新时间为 2019 年 07 月 31 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 lgrevelink/laravel-simple-jwt 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 lgrevelink/laravel-simple-jwt 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 1.82k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2019-07-31