Files
xk-hy-transit-go/docs/FILEAUTH.md
2026-05-28 16:39:51 +08:00

53 lines
1.8 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# FileAuth 上传凭证Ver2.0 §2.3.3
生产仅使用 **§2.3.3**HMAC 对 **encodedPutPolicy** 字符串。FileAuth.java 旧算法HMAC 对 policy JSON**不可用**,不再维护。
## 生产 putPolicyupload profile
```json
{"scope":"<bucket>","deadline":<unix>}
```
- `scope`**仅 bucket 名**(如 `other-doc`**不要** `bucket:filename`
- **无** `returnBody`
- HTTP 上传为 **PDF 二进制体**`Content-Type: application/pdf`**不使用** multipart与 scope 无关
## 五步
| 步 | 说明 |
|----|------|
| 1 | 构造 putPolicyupload profile 见上) |
| 2 | `encodedPutPolicy = urlsafe_base64(putPolicy)` |
| 3 | `sign = HMAC-SHA1(secret, UTF-8(encodedPutPolicy))` |
| 4 | `encodedSign = urlsafe_base64(sign)` |
| 5 | `uploadToken = AccessKey + ':' + encodedSign + ':' + encodedPutPolicy` |
## Base64 填充
| 环境变量 | 说明 |
|----------|------|
| `FILEAUTH_B64=padded`(默认) | URL-safe Base64 **含 `=`**(与文档教学样例一致) |
| `FILEAUTH_B64=raw` | 无填充(联调仍 403 时可试) |
## 文档样例doc profile仅单测
教学样例含 `returnBody``scope=my-bucket:sunflower.jpg`,见 `auth_ver233_test.go` / `FileAuthServiceTest::test_create_upload_token_doc_golden`
## 错误对照
| HTTP body | 含义 |
|-----------|------|
| `forbidden` | forward-goIP / `X-Forward-Token` |
| **`404`(纯文本)+ 403** | 已过 forward**政务云 token 验签失败** |
## Web 调试
- `/fileauth`:生成 upload profile token`?doc=1` 为文档黄金样例
- `/upload`A=Runner 默认 tokenB=本次上传 `tokenInfo``scope` 应为 bucket
实现:[`internal/fileauth`](../internal/fileauth/ver233.go)
## 上传频率
见 [`internal/hyfile/throttle.go`](../internal/hyfile/throttle.go)`FILE_UPLOAD_MIN_INTERVAL`(默认 `10s`)。