@kne/fastify-oidc 0.1.10 → 0.1.12
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
|
@@ -81,6 +81,8 @@ client 只能申请 `allowedResources` 中的资源;子项目 token 的 `aud`
|
|
|
81
81
|
| 只属于一个租户 | 自动选中 |
|
|
82
82
|
| 多个租户 | 前端展示租户列表 |
|
|
83
83
|
| 授权请求带 `tenant_id` 且用户是成员 | 静默切换(可配合 `prompt=none`) |
|
|
84
|
+
| 授权请求带的 `tenant_id` 无效,用户只有一个可用租户 | 自动选中该租户,不展示列表 |
|
|
85
|
+
| 授权请求带的 `tenant_id` 无效,用户有多个可用租户 | 前端展示租户列表(`prompt=none` 时返回 `interaction_required`) |
|
|
84
86
|
| 会话中的租户已不再有效(被移出、关闭) | 重新判断上面几种情况 |
|
|
85
87
|
|
|
86
88
|
token 中的租户相关 claim 以命名空间为前缀(默认 `${ORIGIN}/`,central 模式为 issuer 的 origin):`tenant_id`、`tenant_user_id`、`roles`、`permissions`(按资源服务 `includePermissions` 决定是否携带)。
|
|
@@ -87,6 +87,11 @@ module.exports = async ({ fastify, options, identity, translator, jwks, getLocal
|
|
|
87
87
|
if (await identity.isTenantMember(accountId, requested, scope)) {
|
|
88
88
|
return select(requested);
|
|
89
89
|
}
|
|
90
|
+
// 请求的租户无效(如子应用误传本地租户 id)但只有一个可用租户时直接进入,没得选就不弹选择页
|
|
91
|
+
const { list } = await identity.listTenants(accountId, scope);
|
|
92
|
+
if (list.length === 1) {
|
|
93
|
+
return select(list[0].tenantId);
|
|
94
|
+
}
|
|
90
95
|
return interactionPolicy.Check.REQUEST_PROMPT;
|
|
91
96
|
}
|
|
92
97
|
if (currentTenantId) {
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
const { mapTenantImages } = require('../utils/tenant-images');
|
|
2
|
+
const findMirroredFile = require('../utils/find-mirrored-file');
|
|
2
3
|
|
|
3
4
|
const FAILURE_RETRY_MS = 30 * 1000;
|
|
4
5
|
const FILE_SOURCE = 'oidcHostFileSource';
|
|
@@ -54,7 +55,7 @@ module.exports = ({ fastify, options, serviceClient, userMirror }) => {
|
|
|
54
55
|
const mapping = {};
|
|
55
56
|
for (const [source, url] of Object.entries(fileUrls)) {
|
|
56
57
|
const current = previous[source];
|
|
57
|
-
if (
|
|
58
|
+
if (await findMirroredFile(files, current)) {
|
|
58
59
|
mapping[source] = current;
|
|
59
60
|
continue;
|
|
60
61
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
const crypto = require('node:crypto');
|
|
2
2
|
const { pick } = require('lodash');
|
|
3
|
+
const findMirroredFile = require('../utils/find-mirrored-file');
|
|
3
4
|
|
|
4
5
|
const PROFILE_FIELDS = ['nickname', 'avatar', 'email', 'phone', 'gender', 'birthday', 'description'];
|
|
5
6
|
const USER_FIELDS = ['id', ...PROFILE_FIELDS, 'status'];
|
|
@@ -22,7 +23,7 @@ module.exports = ({ fastify, options, serviceClient }) => {
|
|
|
22
23
|
if (!remote.avatar) {
|
|
23
24
|
return null;
|
|
24
25
|
}
|
|
25
|
-
const mirrored =
|
|
26
|
+
const mirrored = await findMirroredFile(files, current);
|
|
26
27
|
const mirroredSource = mirrored?.options?.[AVATAR_SOURCE];
|
|
27
28
|
if (mirroredSource && mirroredSource === remote.avatar) {
|
|
28
29
|
return current;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 找已拷到本地文件库的文件:记录还在但文件已丢(本地存储随部署目录变化丢失)时视为没有,调用方重新拷贝
|
|
3
|
+
*/
|
|
4
|
+
module.exports = async (files, id) => {
|
|
5
|
+
if (!id) {
|
|
6
|
+
return null;
|
|
7
|
+
}
|
|
8
|
+
const file = await Promise.resolve(files.getFileInstance({ id })).catch(() => null);
|
|
9
|
+
if (!file || typeof files.getFileUrl !== 'function') {
|
|
10
|
+
return file;
|
|
11
|
+
}
|
|
12
|
+
const available = await Promise.resolve(files.getFileUrl({ id })).then(
|
|
13
|
+
() => true,
|
|
14
|
+
() => false
|
|
15
|
+
);
|
|
16
|
+
return available ? file : null;
|
|
17
|
+
};
|