@ohoooho/taoxian-runtime-sdk 0.1.1 → 0.1.2
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/CHANGELOG.md +7 -0
- package/README.md +5 -4
- package/examples/fenshen-http.mjs +1 -1
- package/fenshen.mjs +11 -6
- package/package.json +1 -1
- package/types/fenshen.d.ts +6 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.1.2
|
|
4
|
+
|
|
5
|
+
- `return_to` 不是 OAuth/OIDC 标准,回跳参数改回更短的内部约定 `next`。
|
|
6
|
+
- 仍然只接受 Runtime 同源相对路径,拒绝完整 URL、`//host`、反斜杠和控制字符。
|
|
7
|
+
- `nextPath` 为主 API;0.1.1 的 `returnTo` 保留为 deprecated alias。
|
|
8
|
+
- 原生 `node:http` 示例继续保留,不引入 Express。
|
|
9
|
+
|
|
3
10
|
## 0.1.1
|
|
4
11
|
|
|
5
12
|
- 修复登录回跳参数:移除随意定义的 `next`,改为 `return_to`,仅接受 Runtime 同源相对路径。
|
package/README.md
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
npm install @ohoooho/taoxian-runtime-sdk
|
|
7
7
|
```
|
|
8
8
|
|
|
9
|
-
当前版本:`0.1.
|
|
9
|
+
当前版本:`0.1.2`,license:MIT。Node.js >= 20。浏览器请使用 `@ohoooho/taoxian-runtime-sdk/browser`。
|
|
10
10
|
包是 **ESM-only**;CommonJS 项目请用动态 `import()` 或先转译。自带 TypeScript 声明。
|
|
11
11
|
|
|
12
12
|
## 入口
|
|
@@ -56,7 +56,7 @@ const server = createServer(async (req, res) => {
|
|
|
56
56
|
const user = await auth.authenticate(req);
|
|
57
57
|
if (!user) {
|
|
58
58
|
res.writeHead(302, {
|
|
59
|
-
Location: runtimeLoginUrl(req, {
|
|
59
|
+
Location: runtimeLoginUrl(req, { nextPath: '/' }),
|
|
60
60
|
});
|
|
61
61
|
res.end();
|
|
62
62
|
return;
|
|
@@ -70,7 +70,8 @@ const server = createServer(async (req, res) => {
|
|
|
70
70
|
- Runtime 不可用时返回 503,不会重定向循环
|
|
71
71
|
- 不要自己再实现一套登录页
|
|
72
72
|
- 不要把 Cookie 暴露给浏览器 JS 或日志
|
|
73
|
-
- `
|
|
73
|
+
- `next` 只接受 Runtime 同源的相对路径;跨端口回跳需要正式的 handoff,不用裸 URL 参数
|
|
74
|
+
- `next` 是内部约定,不是 OAuth 标准;接 Logto/OIDC 时用 `state` + `redirect_uri`
|
|
74
75
|
|
|
75
76
|
完整契约见 [`../docs/FENSHEN-INTEGRATION.md`](../docs/FENSHEN-INTEGRATION.md)。
|
|
76
77
|
|
|
@@ -135,7 +136,7 @@ const url = resolveFenshenUiUrl(fenshens[0]);
|
|
|
135
136
|
|
|
136
137
|
```html
|
|
137
138
|
<script type="module">
|
|
138
|
-
import { createRuntimeBrowserClient } from 'https://cdn.jsdelivr.net/npm/@ohoooho/taoxian-runtime-sdk@0.1.
|
|
139
|
+
import { createRuntimeBrowserClient } from 'https://cdn.jsdelivr.net/npm/@ohoooho/taoxian-runtime-sdk@0.1.2/browser.mjs';
|
|
139
140
|
const client = createRuntimeBrowserClient();
|
|
140
141
|
console.log(await client.getStatus());
|
|
141
142
|
</script>
|
|
@@ -15,7 +15,7 @@ const server = createServer(async (req, res) => {
|
|
|
15
15
|
const user = await auth.authenticate(req);
|
|
16
16
|
if (!user) {
|
|
17
17
|
res.writeHead(302, {
|
|
18
|
-
Location: runtimeLoginUrl(req, { runtimeUrl,
|
|
18
|
+
Location: runtimeLoginUrl(req, { runtimeUrl, nextPath: '/' }),
|
|
19
19
|
'Cache-Control': 'no-store',
|
|
20
20
|
});
|
|
21
21
|
res.end();
|
package/fenshen.mjs
CHANGED
|
@@ -54,7 +54,7 @@ export function runtimePublicUrl(req, {
|
|
|
54
54
|
return url.toString();
|
|
55
55
|
}
|
|
56
56
|
|
|
57
|
-
export function
|
|
57
|
+
export function normalizeNextPath(value, { fallback = '/' } = {}) {
|
|
58
58
|
if (!value) return fallback;
|
|
59
59
|
const text = String(value);
|
|
60
60
|
if (!text.startsWith('/') || text.startsWith('//') || text.includes('\\')) return fallback;
|
|
@@ -71,11 +71,12 @@ export function runtimeLoginUrl(req, {
|
|
|
71
71
|
runtimeUrl = process.env.TAOXIAN_RUNTIME_URL || DEFAULT_RUNTIME_URL,
|
|
72
72
|
runtimePort,
|
|
73
73
|
trustProxy = false,
|
|
74
|
-
|
|
74
|
+
nextPath,
|
|
75
|
+
returnTo, // deprecated alias
|
|
75
76
|
} = {}) {
|
|
76
77
|
const url = runtimeBaseUrl(req, { runtimeUrl, runtimePort, trustProxy });
|
|
77
|
-
const path =
|
|
78
|
-
if (path !== '/') url.searchParams.set('
|
|
78
|
+
const path = normalizeNextPath(nextPath ?? returnTo);
|
|
79
|
+
if (path !== '/') url.searchParams.set('next', path);
|
|
79
80
|
return url.toString();
|
|
80
81
|
}
|
|
81
82
|
|
|
@@ -104,7 +105,8 @@ export function createFenshenAuth({
|
|
|
104
105
|
trustProxy = false,
|
|
105
106
|
// For now this is a Runtime-relative path. Cross-service return (fenshen
|
|
106
107
|
// origin + port) needs a proper handoff/state flow, not a raw URL param.
|
|
107
|
-
|
|
108
|
+
loginNextPath,
|
|
109
|
+
loginReturnTo, // deprecated alias
|
|
108
110
|
onUnauthorized,
|
|
109
111
|
onUnavailable,
|
|
110
112
|
} = {}) {
|
|
@@ -121,7 +123,7 @@ export function createFenshenAuth({
|
|
|
121
123
|
res.setHeader('Location', runtimeLoginUrl(req, {
|
|
122
124
|
runtimeUrl,
|
|
123
125
|
trustProxy,
|
|
124
|
-
|
|
126
|
+
nextPath: loginNextPath ?? loginReturnTo ?? '/',
|
|
125
127
|
}));
|
|
126
128
|
return res.end();
|
|
127
129
|
}
|
|
@@ -142,3 +144,6 @@ export function createFenshenAuth({
|
|
|
142
144
|
middleware,
|
|
143
145
|
};
|
|
144
146
|
}
|
|
147
|
+
|
|
148
|
+
// Deprecated alias kept for 0.1.1 consumers.
|
|
149
|
+
export const normalizeReturnTo = normalizeNextPath;
|
package/package.json
CHANGED
package/types/fenshen.d.ts
CHANGED
|
@@ -5,6 +5,8 @@ export interface FenshenAuthOptions {
|
|
|
5
5
|
timeoutMs?: number;
|
|
6
6
|
fetchImpl?: FetchLike;
|
|
7
7
|
trustProxy?: boolean;
|
|
8
|
+
loginNextPath?: string;
|
|
9
|
+
/** @deprecated use loginNextPath */
|
|
8
10
|
loginReturnTo?: string;
|
|
9
11
|
onUnauthorized?: (req: any, res: any) => any;
|
|
10
12
|
onUnavailable?: (req: any, res: any, error: unknown) => any;
|
|
@@ -24,6 +26,8 @@ export interface RuntimePublicUrlOptions {
|
|
|
24
26
|
}
|
|
25
27
|
|
|
26
28
|
export interface RuntimeLoginUrlOptions extends Omit<RuntimePublicUrlOptions, 'path'> {
|
|
29
|
+
nextPath?: string;
|
|
30
|
+
/** @deprecated use nextPath */
|
|
27
31
|
returnTo?: string;
|
|
28
32
|
}
|
|
29
33
|
|
|
@@ -32,6 +36,8 @@ export class FenshenAuthError extends Error {
|
|
|
32
36
|
cause?: unknown;
|
|
33
37
|
}
|
|
34
38
|
|
|
39
|
+
export function normalizeNextPath(value: unknown, options?: { fallback?: string }): string;
|
|
40
|
+
/** @deprecated use normalizeNextPath */
|
|
35
41
|
export function normalizeReturnTo(value: unknown, options?: { fallback?: string }): string;
|
|
36
42
|
export function runtimePublicUrl(req: any, options?: RuntimePublicUrlOptions): string;
|
|
37
43
|
export function runtimeLoginUrl(req: any, options?: RuntimeLoginUrlOptions): string;
|