@kne/fastify-oidc 0.1.3 → 0.1.4
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 +1 -1
- package/libs/resource/authenticate.js +23 -7
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -453,7 +453,7 @@ oidc-provider 的交互地址,303 跳转到 `${ORIGIN}${interactionPage}?uid={
|
|
|
453
453
|
|
|
454
454
|
| 方法 | 说明 |
|
|
455
455
|
|------|------|
|
|
456
|
-
| `authenticate.user` | 校验 `Authorization: Bearer / DPoP
|
|
456
|
+
| `authenticate.user` | 校验 `Authorization: Bearer / DPoP`(SSE 请求即 `Accept: text/event-stream` 且无该头时,读 query 中的 `Authorization` / `DPoP`,供原生 EventSource 使用),填充 `request.user` 与兼容字段;无 token 且 `legacyToken` 时回退 `x-user-token`;拒绝 client 令牌 |
|
|
457
457
|
| `authenticate.tenantUser` | 按 `tenantSource` 填充 `request.tenantUserInfo`;legacy 请求委托给 fastify-tenant |
|
|
458
458
|
| `authenticate.admin` | 委托 fastify-account 的超级管理员校验 |
|
|
459
459
|
| `authenticate.scope(...scopes)` | 返回中间件,校验 token scope |
|
|
@@ -4,18 +4,34 @@ const { createError } = require('../utils/intl');
|
|
|
4
4
|
|
|
5
5
|
const { Unauthorized, Forbidden } = httpErrors;
|
|
6
6
|
|
|
7
|
+
const parseAuthorization = value => {
|
|
8
|
+
const index = value.indexOf(' ');
|
|
9
|
+
const scheme = value.slice(0, index).toLowerCase();
|
|
10
|
+
const token = value.slice(index + 1).trim();
|
|
11
|
+
if (!['bearer', 'dpop'].includes(scheme) || !token) {
|
|
12
|
+
return null;
|
|
13
|
+
}
|
|
14
|
+
return { scheme, token };
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
const isEventStream = request => String(request.headers.accept || '').includes('text/event-stream');
|
|
18
|
+
|
|
19
|
+
// 原生 EventSource 无法设置请求头,SSE 请求允许从 query 读取 Authorization / DPoP
|
|
7
20
|
const extractToken = request => {
|
|
8
21
|
const header = request.headers.authorization;
|
|
9
|
-
if (
|
|
22
|
+
if (header) {
|
|
23
|
+
return parseAuthorization(header);
|
|
24
|
+
}
|
|
25
|
+
if (!isEventStream(request)) {
|
|
10
26
|
return null;
|
|
11
27
|
}
|
|
12
|
-
const
|
|
13
|
-
const
|
|
14
|
-
const
|
|
15
|
-
if (!
|
|
28
|
+
const query = request.query || {};
|
|
29
|
+
const value = query.Authorization || query.authorization;
|
|
30
|
+
const extracted = typeof value === 'string' ? parseAuthorization(value) : null;
|
|
31
|
+
if (!extracted) {
|
|
16
32
|
return null;
|
|
17
33
|
}
|
|
18
|
-
return {
|
|
34
|
+
return Object.assign(extracted, { proof: query.DPoP || query.dpop });
|
|
19
35
|
};
|
|
20
36
|
|
|
21
37
|
/**
|
|
@@ -53,7 +69,7 @@ module.exports = ({ fastify, options, verifier, dpop, revocation, userMirror, se
|
|
|
53
69
|
}
|
|
54
70
|
try {
|
|
55
71
|
await dpop.verify({
|
|
56
|
-
proof: request.headers.dpop,
|
|
72
|
+
proof: extracted.proof || request.headers.dpop,
|
|
57
73
|
method: request.method,
|
|
58
74
|
url: getRequestUrl(request),
|
|
59
75
|
accessToken: extracted.token,
|