@celljs/jwt 4.6.1 → 4.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/README.zh-cn.md +16 -0
  2. package/package.json +2 -2
@@ -0,0 +1,16 @@
1
+ # Cell - JWT 组件
2
+
3
+ `JwtService` 用 `node:crypto` 签名、验证和解码 JSON Web Token(无第三方依赖)。算法:`HS256/384/512`、`RS256/384/512`、`PS256/384/512`、`ES256/384/512` 和 `none`(仅在 `algorithms` 中列出时)。
4
+
5
+ ```yaml
6
+ jwt:
7
+ secret: ${env.JWT_SECRET} # 或 privateKey / publicKey(PEM)
8
+ signOptions:
9
+ expiresIn: 2h
10
+ ```
11
+
12
+ 选项、默认值、检查和错误消息来自 `jsonwebtoken` 包,所以任一方制作的 token 都能用另一方验证:`expiresIn` / `notBefore` / `maxAge` 取秒或 `'2h'`、`'7 days'`;`verify` 检查 `audience`(字符串或 RegExp)、`issuer`、`subject`、`jwtid`、`nonce`,带 `clockTolerance`。失败是 `JsonWebTokenError`、`TokenExpiredError`(`expiredAt`)和 `NotBeforeError`(`date`)。密钥必须符合算法:`HS*` 用 HMAC 密钥、`RS*` / `PS*` 用至少 2048 位的 RSA 密钥(`allowInsecureKeySizes` 允许更少)、`ES*` 用匹配曲线的 EC 密钥。
13
+
14
+ 短于 32 字节的 HMAC `secret`(无 `privateKey`)由 `cell check` 和生产启动(`@celljs/core` 的 `securityChecks`)报告为 `CELL_SECURITY_WEAK_JWT_SECRET`:短密钥可从一个 token 暴力破解。使用 `openssl rand -base64 48` 或 RSA / EC 密钥对。
15
+
16
+ `JwtUtil.sign / verify / decode` 在没有容器的情况下做同样的事。
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@celljs/jwt",
3
- "version": "4.6.1",
3
+ "version": "4.8.0",
4
4
  "description": "",
5
5
  "keywords": [
6
6
  "cell-component"
@@ -32,7 +32,7 @@
32
32
  "watch": "tsc -b -w --preserveWatchOutput"
33
33
  },
34
34
  "dependencies": {
35
- "@celljs/core": "4.6.1"
35
+ "@celljs/core": "4.8.0"
36
36
  },
37
37
  "publishConfig": {
38
38
  "access": "public"