@kne/fastify-oidc 0.1.7 → 0.1.8
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 +2 -2
- package/libs/services/client.js +21 -12
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -289,8 +289,8 @@ oidc-provider 9.x 为 ESM 包,本插件通过动态 `import()` 加载,要求
|
|
|
289
289
|
| includePermissions | boolean | 否 | `false` | 资源服务未设置时,token 是否携带 permissions |
|
|
290
290
|
| defaultResourceScope | string | 否 | `api` | 资源服务默认 scope |
|
|
291
291
|
| seedSelf | boolean | 否 | `true` | 启动时自动登记本项目 SPA client、本项目 API、服务接口资源 |
|
|
292
|
-
| selfClient | object | 否 | `{}` | 覆盖默认 SPA client 的字段与 metadata,如 `{ clientName: '系统名称' }`(默认名称为 `name`);仅首次登记时生效;已存在的 client 只会追加缺失的 `redirect_uris` / `post_logout_redirect_uris`(如 `ORIGIN` 变更),其他字段不覆盖 |
|
|
293
|
-
| clients | array | 否 | `[]` | 启动时登记的 client(已存在则只追加缺失的 `redirect_uris` / `post_logout_redirect_uris`),字段同管理接口 `client/create`,metadata 直接平铺 |
|
|
292
|
+
| selfClient | object | 否 | `{}` | 覆盖默认 SPA client 的字段与 metadata,如 `{ clientName: '系统名称' }`(默认名称为 `name`);仅首次登记时生效;已存在的 client 只会追加缺失的 `redirect_uris` / `post_logout_redirect_uris` / `allowedResources`(如 `ORIGIN` 变更),其他字段不覆盖 |
|
|
293
|
+
| clients | array | 否 | `[]` | 启动时登记的 client(已存在则只追加缺失的 `redirect_uris` / `post_logout_redirect_uris` / `allowedResources`),字段同管理接口 `client/create`,metadata 直接平铺 |
|
|
294
294
|
| resourceServers | array | 否 | `[]` | 启动时登记的资源服务(已存在则跳过) |
|
|
295
295
|
| serviceScopes | array | 否 | `['user:read', 'tenant:read']` | 服务接口资源的 scope |
|
|
296
296
|
| getAuthenticate | function | 否 | 见下文 | 管理接口鉴权,参数为 `client:manage` / `resource-server:manage` / `key:manage` / `session:manage` |
|
package/libs/services/client.js
CHANGED
|
@@ -154,20 +154,29 @@ module.exports = fp(async (fastify, options) => {
|
|
|
154
154
|
});
|
|
155
155
|
};
|
|
156
156
|
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
const
|
|
160
|
-
|
|
157
|
+
const appendMissing = (current, values) => {
|
|
158
|
+
const list = Array.isArray(current) ? current : [];
|
|
159
|
+
const missing = (values || []).filter(value => !list.includes(value));
|
|
160
|
+
return missing.length ? [...list, ...missing] : null;
|
|
161
|
+
};
|
|
162
|
+
|
|
163
|
+
// 已存在的客户端只追加配置中缺失的回调地址与资源(如 ORIGIN 变更),不覆盖管理端维护的其他字段
|
|
164
|
+
const mergeSeed = async (item, { metadata, allowedResources }) => {
|
|
165
|
+
const nextMetadata = Object.assign({}, item.metadata);
|
|
166
|
+
const patch = {};
|
|
161
167
|
['redirect_uris', 'post_logout_redirect_uris'].forEach(key => {
|
|
162
|
-
const
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
changed = true;
|
|
168
|
+
const next = appendMissing(nextMetadata[key], metadata[key]);
|
|
169
|
+
if (next) {
|
|
170
|
+
nextMetadata[key] = next;
|
|
171
|
+
patch.metadata = nextMetadata;
|
|
167
172
|
}
|
|
168
173
|
});
|
|
169
|
-
|
|
170
|
-
|
|
174
|
+
const nextResources = appendMissing(item.allowedResources, allowedResources);
|
|
175
|
+
if (nextResources) {
|
|
176
|
+
patch.allowedResources = nextResources;
|
|
177
|
+
}
|
|
178
|
+
if (Object.keys(patch).length) {
|
|
179
|
+
await item.update(patch);
|
|
171
180
|
}
|
|
172
181
|
};
|
|
173
182
|
|
|
@@ -175,7 +184,7 @@ module.exports = fp(async (fastify, options) => {
|
|
|
175
184
|
for (const { clientId, clientName, clientSecret, allowedResources, description, ...metadata } of clients || []) {
|
|
176
185
|
const item = await models.client.findOne({ where: { clientId } });
|
|
177
186
|
if (item) {
|
|
178
|
-
await
|
|
187
|
+
await mergeSeed(item, { metadata, allowedResources });
|
|
179
188
|
continue;
|
|
180
189
|
}
|
|
181
190
|
await create({ clientId, clientName, clientSecret, metadata, allowedResources, description });
|