klimesf/nette-jwt-user-storage
Composer 安装命令:
composer require klimesf/nette-jwt-user-storage
包简介
Nette IUserStorage implementation using JWT instead of sessions.
README 文档
README
DISCONTINUED
This repository is abandoned. You can use slepic's fork https://github.com/slepic/nette-jwt-user-storage.
Nette IUserStorage implementation using JWT access token instead of PHP sessions.
Disclaimer: If you don't know what JWT is, please refer to JWT draft or to JWT homepage.
On user login, the application stores jwt_access_token cookie instead of bad old PHPSESSID one.
The cookie contains an encoded JWT signed by the application. The user authentication is then based
on verifying the JWT rather than the session.
Warning: CSRF protection rules still apply!
This means you no longer need to solve PHP session implementation, scaling and testing problems.
All the things that you would normally store in the SessionStorage can be stored in a key-value
storage, where the JWT is a key.
This also means your application is ready to become SPA in the future. :)
Configuration
Register the extension in your config.neon.
extensions: jwtUserStorage: Klimesf\Security\DI\JWTUserStorageExtension
Then configure its required properties.
JWTUserStorage: privateKey: 'secret-cat' # this secret is used to sign the JWT algorithm: 'HS256' # this is the signing algorithm
Both the JWT and the cookie in which it's stored is by default set to expire in 20 days. If you want to fiddle
with expiration time, use expiration option:
JWTUserStorage: expiration: 20 days # sets JWT and cookie expiration time to 20 days (this is the default option) expiration: 20 minutes # sets JWT and cookie expiration time to 20 minutes expiration: false # sets JWT and cookie to never expire
By default, jti and iat (see JWT draft) are added
to your JWTs. If you don't want to use them, set generateJti and generateIat options to false.
JWTUserStorage: generateJti: false # disables jti generation for your JWT access tokens generateIat: false # disables iat generation for your JWT access tokens
If you want to define your own Nette\Security\IIdentity serializer, which serializes your identity implementation
into the JWT body, you can implement Klimesf\Security\IIdentitySerializer
namespace Your\Own;
class IdentitySerializer implements \Klimesf\Security\IIdentitySerializer
{
// ...
}
and register it in configuration.
JWTUserStorage: identitySerializer: Your\Own\IdentitySerializer
And that's it, you're ready to go!
Known issues
- If you are developing an app with JWT User Storage and you still see
PHPSESSIDin your cookies, it's probably because Tracy\Tracy uses it.
Discussion threads
- Czech discussion thread on Nette Forum
Literature
klimesf/nette-jwt-user-storage 适用场景与选型建议
klimesf/nette-jwt-user-storage 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 47 次下载、GitHub Stars 达 8, 最近一次更新时间为 2015 年 08 月 21 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 klimesf/nette-jwt-user-storage 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 klimesf/nette-jwt-user-storage 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 47
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 8
- 点击次数: 17
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2015-08-21