loginbase 1.0.0 → 1.1.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.
package/README.md CHANGED
@@ -39,7 +39,7 @@ Kotlin 包 wang.harlon.loginbase
39
39
 
40
40
  ## 状态与路线
41
41
 
42
- **落地第 1 步已完成**(2026-08-12):`loginbase@0.1.1` 上线 npm(trusted publishing + provenance),Tono-Server 已切换依赖并部署生产(其 67 测试全绿即抽取验收)。下一步 = 第 2 步钩子化。落地顺序:
42
+ **落地第 1、2 步已完成**(2026-08-12):`loginbase@1.0.0` 上线 npm(钩子化 + zh/en 模板 + github-oauth + TTL 配置,协议契约见 docs/protocol.md),Tono-Server 已接 onVerified 钩子并部署生产。下一步 = 第 3 步 TrendingAI 接入。落地顺序:
43
43
 
44
44
  1. 从 Tono-Server 平移服务端代码与测试,Tono-Server 改为依赖本包(其现有测试即抽取验收)
45
45
  2. 钩子化(`onVerified` 用户回调)+ zh/en 邮件模板 + github-oauth 可选插件
package/dist/config.d.ts CHANGED
@@ -3,6 +3,13 @@ export interface VerifiedIdentity {
3
3
  email: string;
4
4
  provider: "email" | "github";
5
5
  providerUserId?: string;
6
+ /**
7
+ * OAuth provider 的公开档案(GitHub = /user 响应裁剪到建档白名单:
8
+ * id/login/name/email/avatar_url/bio/html_url/company/location/blog/
9
+ * twitter_username/created_at),供 App 建档取资料;email provider 恒缺省。
10
+ * 认证视图的敏感字段(私有统计、2FA 状态等)在库边界内剔除。
11
+ */
12
+ providerProfile?: unknown;
6
13
  requestMeta: {
7
14
  ip?: string;
8
15
  userAgent?: string;
@@ -34,6 +34,30 @@ function redirectAllowed(redirect, github) {
34
34
  function withParam(url, key, value) {
35
35
  return `${url}${url.includes("?") ? "&" : "?"}${key}=${encodeURIComponent(value)}`;
36
36
  }
37
+ // providerProfile 只透传建档需要的公开档案白名单——GET /user 的认证视图含
38
+ // two_factor_authentication、私有仓库统计等敏感字段,不该流出库边界。
39
+ const PROFILE_FIELDS = [
40
+ "id",
41
+ "login",
42
+ "name",
43
+ "email",
44
+ "avatar_url",
45
+ "bio",
46
+ "html_url",
47
+ "company",
48
+ "location",
49
+ "blog",
50
+ "twitter_username",
51
+ "created_at",
52
+ ];
53
+ function publicProfile(user) {
54
+ const out = {};
55
+ for (const key of PROFILE_FIELDS) {
56
+ if (user[key] !== undefined)
57
+ out[key] = user[key];
58
+ }
59
+ return out;
60
+ }
37
61
  export function registerGithubOauth(auth, getConfig, basePath) {
38
62
  const cfg = (c) => getConfig(c.env);
39
63
  const github = (c) => cfg(c).socials?.github;
@@ -115,6 +139,7 @@ export function registerGithubOauth(auth, getConfig, basePath) {
115
139
  email: email.trim().toLowerCase(),
116
140
  provider: "github",
117
141
  providerUserId: String(ghUser.id),
142
+ providerProfile: publicProfile(ghUser), // GitHub /user 公开档案白名单字段
118
143
  requestMeta: { ip, userAgent },
119
144
  });
120
145
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "loginbase",
3
- "version": "1.0.0",
3
+ "version": "1.1.0",
4
4
  "description": "Shared login foundation for Cloudflare Workers: email OTP + social OAuth + session management, as a Hono sub-app factory.",
5
5
  "type": "module",
6
6
  "license": "MIT",