sop/jwx
Composer 安装命令:
composer require sop/jwx
包简介
A PHP library for JSON web tokens (JWT) with signature (JWS) and encryption (JWE) support.
关键字:
README 文档
README
A PHP library for JSON web tokens (JWT) with signature (JWS) and encryption (JWE) support.
Also implements unencoded payload option (RFC 7797).
Features
- Signing and signature validation (JWS)
- HMAC, RSA and EC
- Encryption and decryption with compression and integrity protection (JWE)
- AES
- Claims validation
- Configurable with sensible defaults
- JSON Web Keys (JWK)
- Convert PEM encoded keys to JWK and vice versa
Supported algorithms
- Signature
- HMAC with SHA-256, SHA-384 and SHA-512
- RSASSA-PKCS1-v1_5 with SHA-256, SHA-384 and SHA-512
- ECDSA with P-256, P-384 and P-521 curves
- Content encryption
- AES-CBC with 128, 192 and 256-bit key sizes
- AES-GCM with 128, 192 and 256-bit key sizes
- Key management
- Shared symmetric key (direct)
- RSAES-PKCS1-v1_5
- RSAES OAEP
- AES Key Wrap with 128, 192 and 256-bit key sizes
- AES-GCM key encryption with 128, 192 and 256-bit key sizes
- Password-based key encryption (PBES2 with AES Key Wrap)
- Compression
- DEFLATE
Requirements
- PHP >=7.2
- openssl
- hash
- sop/crypto-types
- sop/crypto-encoding
- sop/aes-kw
- sop/gcm
Installation
This library is available on Packagist.
composer require sop/jwx
Usage
Claims class holds Claim objects that represent the claims.
The claims shall be encoded into a JWT which may further be
signed or encrypted, producing a JWS or a JWE respectively.
JWS and JWE may also be used to carry arbitrary payload, not just JSON claims.
Code examples
Simple JWT
Parse JWT from https://jwt.io/ HS512 example.
$jwt = new JWT($token); // create context for the claims validation // 'your-512-bit-secret' key is used to verify the signature $ctx = ValidationContext::fromJWK( SymmetricKeyJWK::fromKey('your-512-bit-secret')); // validate claims $claims = $jwt->claims($ctx); // print value of the subject claim echo $claims->subject()->value();
Additional Validation
Parse the same token as above but additionally validate subject and admin claims.
$jwt = new JWT($token); // validate that the subject is "1234567890" // validate that the admin claim is true using explicitly provided validator $ctx = ValidationContext::fromJWK( SymmetricKeyJWK::fromKey('your-512-bit-secret'), ['sub' => '1234567890'] )->withConstraint('admin', true, new EqualsValidator()); // validate and print all claims $claims = $jwt->claims($ctx); foreach ($claims as $claim) { printf("%s: %s\n", $claim->name(), $claim->value()); }
More Examples
See /examples
directory for more examples.
- Create a signed JWT
- Consume a signed JWT
- Create an encrypted JWT
- Consume an encrypted JWT
- Create a nested JWT
- Consume a nested JWT
- Encrypt arbitrary data
- Decrypt arbitrary data
License
This project is licensed under the MIT License.
sop/jwx 适用场景与选型建议
sop/jwx 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 283.18k 次下载、GitHub Stars 达 25, 最近一次更新时间为 2016 年 04 月 13 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「json」 「token」 「jwt」 「JSON Web Token」 「JSON Web Signature」 「JSON Web Encryption」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 sop/jwx 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 sop/jwx 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 sop/jwx 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Kinikit - PHP Application development framework MVC component
A simple library to decode and parse Apple Sign In client tokens.
ext-json wrapper with sane defaults
A package for validating Google Cloud's JWT provided by webhooks
JSON Web Token Authentication for Laravel and Lumen
A package to cast json fields, each sub-keys is castable
统计信息
- 总下载量: 283.18k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 26
- 点击次数: 28
- 依赖项目数: 4
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2016-04-13