@rc-tool/unified-auth-hosted-service 0.2.4 → 0.2.5
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 +95 -3
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -55,12 +55,104 @@ pnpm dlx @rc-tool/unified-auth-hosted-service doctor
|
|
|
55
55
|
|
|
56
56
|
The default store is file-based. Install `@rc-tool/unified-auth-prisma-store` only when `AUTH_STORE_PROVIDER=prisma`.
|
|
57
57
|
|
|
58
|
-
##
|
|
58
|
+
## 配置信息
|
|
59
59
|
|
|
60
|
-
|
|
60
|
+
`@rc-tool/unified-auth-hosted-service` 负责在业务项目里挂载登录页和 `/api/auth/*` 路由。业务项目需要把下面这些配置放进自己的 `.env.local` / `.env.example`,也可以通过 CLI 自动追加缺失项:
|
|
61
|
+
|
|
62
|
+
```bash
|
|
63
|
+
pnpm dlx @rc-tool/unified-auth-hosted-service init --app ai-pm --redirect http://localhost:3004/
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
### 登录页背景图
|
|
67
|
+
|
|
68
|
+
Hosted Auth 登录页默认带兜底背景图,也支持业务项目覆盖。最简单的方式是在业务项目环境变量里配置:
|
|
61
69
|
|
|
62
70
|
```env
|
|
63
71
|
AUTH_LOGIN_BACKGROUND_URL=https://cdn.example.com/auth/login-bg.jpg
|
|
64
72
|
```
|
|
65
73
|
|
|
66
|
-
|
|
74
|
+
然后在 route handler 中传给 `appearance.backgroundImageUrl`:
|
|
75
|
+
|
|
76
|
+
```ts
|
|
77
|
+
export const hostedAuth = createHostedAuthRouteHandlers({
|
|
78
|
+
appearance: {
|
|
79
|
+
backgroundImageUrl: process.env.AUTH_LOGIN_BACKGROUND_URL,
|
|
80
|
+
},
|
|
81
|
+
applications: [
|
|
82
|
+
{
|
|
83
|
+
clientId: process.env.AUTH_CLIENT_ID ?? "ai-pm",
|
|
84
|
+
name: process.env.AUTH_CLIENT_NAME ?? "AI PM",
|
|
85
|
+
redirectURI: process.env.AUTH_ALLOWED_REDIRECT_URI ?? "http://localhost:3004/",
|
|
86
|
+
},
|
|
87
|
+
],
|
|
88
|
+
authBaseURL: process.env.AUTH_SERVICE_URL ?? "http://localhost:3004",
|
|
89
|
+
sessionSecret: process.env.AUTH_SESSION_SECRET!,
|
|
90
|
+
store: createFileAuthStore({
|
|
91
|
+
filePath: process.env.AUTH_STORE_FILE ?? ".auth/unified-auth-store.json",
|
|
92
|
+
}),
|
|
93
|
+
});
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
如果一个 Auth Service 服务多个业务应用,可以给每个 `applications[]` 单独配置:
|
|
97
|
+
|
|
98
|
+
```ts
|
|
99
|
+
applications: [
|
|
100
|
+
{
|
|
101
|
+
appearance: {
|
|
102
|
+
backgroundImageUrl: "https://cdn.example.com/ai-pm-login.jpg",
|
|
103
|
+
},
|
|
104
|
+
clientId: "ai-pm",
|
|
105
|
+
name: "AI PM",
|
|
106
|
+
redirectURI: "http://localhost:3004/",
|
|
107
|
+
},
|
|
108
|
+
{
|
|
109
|
+
appearance: {
|
|
110
|
+
backgroundImageUrl: "https://cdn.example.com/admin-login.jpg",
|
|
111
|
+
},
|
|
112
|
+
clientId: "admin-console",
|
|
113
|
+
name: "Admin Console",
|
|
114
|
+
redirectURI: "https://admin.example.com/",
|
|
115
|
+
},
|
|
116
|
+
],
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
配置优先级是:
|
|
120
|
+
|
|
121
|
+
1. `applications[].appearance.backgroundImageUrl`
|
|
122
|
+
2. `createHostedAuthRouteHandlers({ appearance.backgroundImageUrl })`
|
|
123
|
+
3. SDK 默认背景图
|
|
124
|
+
|
|
125
|
+
### 业务应用配置
|
|
126
|
+
|
|
127
|
+
| 环境变量 | 作用 |
|
|
128
|
+
| --- | --- |
|
|
129
|
+
| `AUTH_SERVICE_URL` | Auth Service 地址。内嵌模式通常就是业务项目自己的 origin。 |
|
|
130
|
+
| `AUTH_CLIENT_ID` | 当前业务应用 id,例如 `ai-pm`。 |
|
|
131
|
+
| `AUTH_CLIENT_NAME` | 登录页展示名称,例如 `AI PM`。 |
|
|
132
|
+
| `AUTH_ALLOWED_REDIRECT_URI` | 登录成功后允许回跳的地址。 |
|
|
133
|
+
|
|
134
|
+
### Session 和 Store 配置
|
|
135
|
+
|
|
136
|
+
| 环境变量 | 作用 |
|
|
137
|
+
| --- | --- |
|
|
138
|
+
| `AUTH_SESSION_SECRET` | session cookie 签名密钥,CLI 会自动生成。 |
|
|
139
|
+
| `AUTH_ALLOW_DEV_LOGIN` | 是否允许开发账号登录,生产环境建议设置为 `false`。 |
|
|
140
|
+
| `AUTH_STORE_PROVIDER` | 认证数据存储方式,默认 `file`,可选 `prisma`。 |
|
|
141
|
+
| `AUTH_STORE_FILE` | file store 的 JSON 文件路径,默认 `.auth/unified-auth-store.json`。 |
|
|
142
|
+
| `AUTH_DATABASE_URL` | Prisma store 的认证库 PostgreSQL 连接串。 |
|
|
143
|
+
|
|
144
|
+
### OAuth Provider 配置
|
|
145
|
+
|
|
146
|
+
| Provider | 环境变量 |
|
|
147
|
+
| --- | --- |
|
|
148
|
+
| 飞书 | `FEISHU_APP_ID`、`FEISHU_APP_SECRET`、`FEISHU_REDIRECT_URI` |
|
|
149
|
+
| Google | `GOOGLE_CLIENT_ID`、`GOOGLE_CLIENT_SECRET`、`GOOGLE_REDIRECT_URI` |
|
|
150
|
+
| GitHub | `GITHUB_CLIENT_ID`、`GITHUB_CLIENT_SECRET`、`GITHUB_REDIRECT_URI` |
|
|
151
|
+
|
|
152
|
+
内嵌模式下 callback 一般挂在业务项目自己的 `/api/auth/*` 路由:
|
|
153
|
+
|
|
154
|
+
```env
|
|
155
|
+
FEISHU_REDIRECT_URI=http://localhost:3004/api/auth/feishu/callback
|
|
156
|
+
GOOGLE_REDIRECT_URI=http://localhost:3004/api/auth/google/callback
|
|
157
|
+
GITHUB_REDIRECT_URI=http://localhost:3004/api/auth/github/callback
|
|
158
|
+
```
|