@pubinfo/module-auth 2.2.0-beta.5 → 2.2.1

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.md +73 -0
  2. package/package.json +3 -3
package/README.md ADDED
@@ -0,0 +1,73 @@
1
+ # @pubinfo/module-auth
2
+
3
+ Pubinfo 的认证模块,核心是“认证客户端 + 路由模块”两层能力:一层负责统一登录、回调认证、二维码渲染;一层负责把 `/auth/:type` 回调页和登录跳转逻辑挂到应用里。
4
+
5
+ ## 它在做什么
6
+
7
+ - 提供 `createAuth()`,统一封装第三方登录 Provider
8
+ - 提供 `createAuthModule()`,把认证回调页和登录前跳转逻辑注册到 Pubinfo 应用
9
+ - 内置多种 Provider:`FourA`、`DingZJ`、`Sso`、`Credentials`、`DefaultCredentials`
10
+ - 支持插件扩展,目前内置 `twoFactor` 双因子认证插件
11
+ - 保留旧版 `auth()` 和一组兼容导出,但代码里已经标记为 deprecated
12
+
13
+ ## 推荐接入方式
14
+
15
+ ```ts
16
+ import { createAuth, createAuthModule } from '@pubinfo/module-auth';
17
+ import { FourA } from '@pubinfo/module-auth/providers';
18
+
19
+ const authClient = createAuth({
20
+ baseURL: import.meta.env.VITE_APP_API_BASEURL,
21
+ providers: [
22
+ FourA({
23
+ clientId: 'your-client-id',
24
+ redirectUri: 'https://example.com/#/auth/4A',
25
+ }),
26
+ ],
27
+ });
28
+
29
+ export function setupAuth() {
30
+ return createAuthModule(authClient, {
31
+ pages: {
32
+ signIn: '/login',
33
+ },
34
+ redirectTo: '/',
35
+ });
36
+ }
37
+ ```
38
+
39
+ ## 工作方式
40
+
41
+ - `createAuth()` 负责根据 provider 执行 `signIn`、`authenticate`、`renderQRCode`、`redirect`
42
+ - `createAuthModule()` 会注册 `/auth/:type` 页面
43
+ - 当访问登录页路径时,如果存在 `cas` 类型 provider,会自动重定向到统一登录页
44
+ - 当回调页认证成功时,会把 token 写入 `userStore`,然后跳转到 `redirect` 或默认目标页
45
+
46
+ ## 内置 Provider
47
+
48
+ - `FourA`: 4A 统一认证
49
+ - `DingZJ`: 浙政钉扫码登录,支持 `redirect` 和 `embed`
50
+ - `Sso`: SSO 单点登录
51
+ - `Credentials`: 自定义凭证登录 provider 外壳
52
+ - `DefaultCredentials`: 对接底座默认用户名密码登录
53
+
54
+ ## 插件扩展
55
+
56
+ `createAuth()` 支持 `plugins`。目前内置:
57
+
58
+ - `twoFactor`: 扩展出 `twoFactor.sendOtp()` 和 `twoFactor.verifyOtp()`
59
+
60
+ ```ts
61
+ import { createAuth } from '@pubinfo/module-auth';
62
+ import { twoFactor } from '@pubinfo/module-auth/plugins';
63
+ ```
64
+
65
+ ## 导出
66
+
67
+ - `createAuthModule`
68
+ - `createAuth`
69
+ - `LoginWithFourA`
70
+ - `auth`
71
+ - `authenticate` / `redirect` / `renderQRCode` / `signIn`
72
+
73
+ 其中最后四个兼容旧用法,但应优先迁移到 `authClient.xxx`。
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@pubinfo/module-auth",
3
3
  "type": "module",
4
- "version": "2.2.0-beta.5",
4
+ "version": "2.2.1",
5
5
  "exports": {
6
6
  ".": {
7
7
  "types": "./dist/index.d.ts",
@@ -31,10 +31,10 @@
31
31
  "node": "^20.19.0 || >=22.12.0"
32
32
  },
33
33
  "peerDependencies": {
34
- "pubinfo": "2.2.0-beta.5"
34
+ "pubinfo": "2.2.1"
35
35
  },
36
36
  "devDependencies": {
37
- "pubinfo": "2.2.0-beta.5"
37
+ "pubinfo": "2.2.1"
38
38
  },
39
39
  "scripts": {
40
40
  "dev": "pubinfo build --watch",