feat(dcauth): 新增常驻托盘客户端与版本显示
Windows 改为单实例托盘常驻,协议唤起只弹一个确认窗口;补充 macOS 后台守护进程 与客户端版本显示。
This commit is contained in:
+66
-13
@@ -1,38 +1,84 @@
|
||||
# DCAuth Windows 客户端
|
||||
# DCAuth 客户端
|
||||
|
||||
三个系统共用的设备认证客户端,通过 `dcauth://` 协议被浏览器唤起。
|
||||
|
||||
## 运行方式
|
||||
|
||||
- **Windows**:GUI 常驻程序。启动后进入系统托盘,通过协议唤起时只出现一个登录确认窗口;成功后在托盘气泡中提示,不再连续弹多个消息框。
|
||||
- **macOS**:后台常驻进程,使用系统图形对话框确认登录。重复执行命令会转发给已有进程,不会叠加实例。
|
||||
|
||||
## 构建
|
||||
|
||||
Windows x64:
|
||||
|
||||
```bash
|
||||
cd apps/dcauth
|
||||
GOOS=windows GOARCH=amd64 go build -trimpath -ldflags "-H windowsgui -s -w" -o dist/DCAuth.exe .
|
||||
x86_64-w64-mingw32-windres --codepage=65001 versioninfo.rc \
|
||||
-O coff -o versioninfo_windows_amd64.syso
|
||||
CGO_ENABLED=0 GOOS=windows GOARCH=amd64 \
|
||||
go build -trimpath -ldflags "-H windowsgui -s -w" \
|
||||
-o dist/DCAuth.exe .
|
||||
```
|
||||
|
||||
ARM64:
|
||||
版本号统一在 `main.go` 的 `clientVersion` 和 `versioninfo.rc` 中维护。`DCAuth.exe` 右键“属性 → 详细信息”会显示文件版本和产品版本,托盘菜单、设备信息及确认窗口也会显示当前版本。
|
||||
|
||||
Windows ARM64:
|
||||
|
||||
```bash
|
||||
GOOS=windows GOARCH=arm64 go build -trimpath -ldflags "-H windowsgui -s -w" -o dist/DCAuth-arm64.exe .
|
||||
CGO_ENABLED=0 GOOS=windows GOARCH=arm64 \
|
||||
go build -trimpath -ldflags "-H windowsgui -s -w" \
|
||||
-o dist/DCAuth-arm64.exe .
|
||||
```
|
||||
|
||||
## 首次运行
|
||||
macOS 通用二进制:
|
||||
|
||||
直接双击 exe 会:
|
||||
```bash
|
||||
CGO_ENABLED=0 GOOS=darwin GOARCH=arm64 \
|
||||
go build -trimpath -ldflags "-s -w" -o /tmp/DCAuth-macos-arm64 .
|
||||
|
||||
CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 \
|
||||
go build -trimpath -ldflags "-s -w" -o /tmp/DCAuth-macos-amd64 .
|
||||
|
||||
lipo -create -output dist/DCAuth-macos \
|
||||
/tmp/DCAuth-macos-arm64 /tmp/DCAuth-macos-amd64
|
||||
|
||||
chmod +x dist/DCAuth-macos
|
||||
codesign --force --sign - dist/DCAuth-macos
|
||||
```
|
||||
|
||||
## Windows 首次运行
|
||||
|
||||
直接运行一次 `DCAuth.exe`:
|
||||
|
||||
- 注册 `dcauth://` 协议到当前 Windows 用户。
|
||||
- 生成 Ed25519 设备密钥,使用 Windows DPAPI 加密保存在 `%LOCALAPPDATA%\DCAuth\device.key`。
|
||||
- 显示设备码和机器码,并复制到剪贴板。
|
||||
- 进入系统托盘后台运行,不弹设备信息窗口。
|
||||
|
||||
托盘操作:
|
||||
|
||||
- 双击图标:查看设备码和机器码,并复制到剪贴板。
|
||||
- 右键菜单:查看设备码、退出 DCAuth。
|
||||
- 浏览器登录:只弹出一个确认窗口;点击“确定”后显示成功气泡,点击“取消”则拒绝。
|
||||
- 再次唤起协议:第二个进程会把请求转交给常驻进程,然后立即退出。
|
||||
|
||||
## macOS 开发调试
|
||||
|
||||
Mac 上不需要安装 Windows exe,也不需要注册自定义协议。登录页在开发模式会显示一条 `dcauth://...` 链接,复制后执行:
|
||||
登录页在开发模式会显示一条 `dcauth://...` 链接。复制后在终端执行:
|
||||
|
||||
```bash
|
||||
cd apps/dcauth
|
||||
go run . "dcauth://authorize?app=order_site&challenge_id=...&challenge=...&api=http%3A%2F%2Flocalhost%3A5173"
|
||||
./dist/DCAuth-macos "dcauth://authorize?app=order_site&challenge_id=...&challenge=...&api=http%3A%2F%2Flocalhost"
|
||||
```
|
||||
|
||||
客户端会提示确认,然后直接调用本地 Vite 代理的 `/api/dcauth/authorize`,完成本机签名。
|
||||
首次执行会启动后台进程并显示图形确认框;命令本身会立即返回。后续协议请求会转发给这个后台进程。
|
||||
|
||||
停止后台进程:
|
||||
|
||||
```bash
|
||||
./dist/DCAuth-macos --exit
|
||||
```
|
||||
|
||||
macOS 当前仍是开发版:私钥明文保存在用户配置目录的 `DCAuth/device.key`,且浏览器不会自动拉起程序,需要从登录页复制命令执行。
|
||||
|
||||
如果只是测后台业务,不想每次都走短信和设备验证,可以在“后台用户”里把测试账号设为 **技术测试**。该账号只使用账号密码登录;正式账号仍必须走短信 + DCAuth。
|
||||
|
||||
@@ -44,7 +90,7 @@ go run . "dcauth://authorize?app=order_site&challenge_id=...&challenge=...&api=h
|
||||
dcauth://authorize?app=order_site&challenge_id=...&challenge=...&api=https%3A%2F%2Forder.khhao.com
|
||||
```
|
||||
|
||||
客户端校验 app 和 api 白名单后,弹出确认框,签名并提交到:
|
||||
客户端校验 app 和 api 白名单后,弹出一次确认框,签名并提交到:
|
||||
|
||||
```text
|
||||
POST /api/dcauth/authorize
|
||||
@@ -60,11 +106,18 @@ POST /api/dcauth/authorize
|
||||
| `live_hub` | `https://live.khhao.com` |
|
||||
| `affiliate_dash` | `https://skin.khhao.com` |
|
||||
|
||||
本地开发入口已内置在 `main.go` 的 `appRegistry` 中,包括 `http://localhost`、`http://127.0.0.1`、`http://192.168.10.6` 及对应 Vite 端口。
|
||||
本地开发入口已内置在 `main.go` 的 `appRegistry` 中,包括 `http://localhost`、`http://localhost/`、`http://127.0.0.1`、`http://192.168.10.6` 及对应 Vite 端口。
|
||||
|
||||
## 验证
|
||||
|
||||
```bash
|
||||
go test ./...
|
||||
CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build -trimpath -ldflags "-H windowsgui -s -w" -o dist/DCAuth.exe .
|
||||
```
|
||||
|
||||
## 安全说明
|
||||
|
||||
- 私钥不离开本机,使用 DPAPI 保护。
|
||||
- 私钥不离开本机,Windows 使用 DPAPI 保护。
|
||||
- 服务端只保存公钥和机器码哈希/脱敏值。
|
||||
- 机器码采集主板 UUID、MachineGuid、主板/BIOS/系统盘序列号、CPU ID,不上传原始序列号。
|
||||
- 正式分发前建议使用代码签名证书,避免 SmartScreen 和杀毒软件误报。
|
||||
|
||||
Reference in New Issue
Block a user