@nocobase/plugin-idp-oauth 2.1.0-alpha.17 → 2.1.0-alpha.19
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/build.config.ts +1 -1
- package/dist/externalVersion.js +6 -4
- package/dist/node_modules/light-my-request/package.json +1 -1
- package/dist/node_modules/undici/LICENSE +21 -0
- package/dist/node_modules/undici/README.md +741 -0
- package/dist/node_modules/undici/docs/docs/api/Agent.md +84 -0
- package/dist/node_modules/undici/docs/docs/api/BalancedPool.md +99 -0
- package/dist/node_modules/undici/docs/docs/api/CacheStorage.md +30 -0
- package/dist/node_modules/undici/docs/docs/api/CacheStore.md +164 -0
- package/dist/node_modules/undici/docs/docs/api/Client.md +285 -0
- package/dist/node_modules/undici/docs/docs/api/ClientStats.md +27 -0
- package/dist/node_modules/undici/docs/docs/api/Connector.md +115 -0
- package/dist/node_modules/undici/docs/docs/api/ContentType.md +57 -0
- package/dist/node_modules/undici/docs/docs/api/Cookies.md +101 -0
- package/dist/node_modules/undici/docs/docs/api/Debug.md +62 -0
- package/dist/node_modules/undici/docs/docs/api/DiagnosticsChannel.md +315 -0
- package/dist/node_modules/undici/docs/docs/api/Dispatcher.md +1392 -0
- package/dist/node_modules/undici/docs/docs/api/EnvHttpProxyAgent.md +159 -0
- package/dist/node_modules/undici/docs/docs/api/Errors.md +49 -0
- package/dist/node_modules/undici/docs/docs/api/EventSource.md +45 -0
- package/dist/node_modules/undici/docs/docs/api/Fetch.md +60 -0
- package/dist/node_modules/undici/docs/docs/api/GlobalInstallation.md +139 -0
- package/dist/node_modules/undici/docs/docs/api/H2CClient.md +263 -0
- package/dist/node_modules/undici/docs/docs/api/MockAgent.md +603 -0
- package/dist/node_modules/undici/docs/docs/api/MockCallHistory.md +197 -0
- package/dist/node_modules/undici/docs/docs/api/MockCallHistoryLog.md +43 -0
- package/dist/node_modules/undici/docs/docs/api/MockClient.md +81 -0
- package/dist/node_modules/undici/docs/docs/api/MockErrors.md +12 -0
- package/dist/node_modules/undici/docs/docs/api/MockPool.md +555 -0
- package/dist/node_modules/undici/docs/docs/api/Pool.md +84 -0
- package/dist/node_modules/undici/docs/docs/api/PoolStats.md +35 -0
- package/dist/node_modules/undici/docs/docs/api/ProxyAgent.md +229 -0
- package/dist/node_modules/undici/docs/docs/api/RedirectHandler.md +93 -0
- package/dist/node_modules/undici/docs/docs/api/RetryAgent.md +50 -0
- package/dist/node_modules/undici/docs/docs/api/RetryHandler.md +118 -0
- package/dist/node_modules/undici/docs/docs/api/RoundRobinPool.md +145 -0
- package/dist/node_modules/undici/docs/docs/api/SnapshotAgent.md +616 -0
- package/dist/node_modules/undici/docs/docs/api/Socks5ProxyAgent.md +274 -0
- package/dist/node_modules/undici/docs/docs/api/Util.md +25 -0
- package/dist/node_modules/undici/docs/docs/api/WebSocket.md +141 -0
- package/dist/node_modules/undici/docs/docs/api/api-lifecycle.md +91 -0
- package/dist/node_modules/undici/docs/docs/best-practices/client-certificate.md +64 -0
- package/dist/node_modules/undici/docs/docs/best-practices/crawling.md +58 -0
- package/dist/node_modules/undici/docs/docs/best-practices/mocking-request.md +190 -0
- package/dist/node_modules/undici/docs/docs/best-practices/proxy.md +127 -0
- package/dist/node_modules/undici/docs/docs/best-practices/undici-vs-builtin-fetch.md +224 -0
- package/dist/node_modules/undici/docs/docs/best-practices/writing-tests.md +63 -0
- package/dist/node_modules/undici/index-fetch.js +65 -0
- package/dist/node_modules/undici/index.d.ts +3 -0
- package/dist/node_modules/undici/index.js +234 -0
- package/dist/node_modules/undici/lib/api/abort-signal.js +59 -0
- package/dist/node_modules/undici/lib/api/api-connect.js +110 -0
- package/dist/node_modules/undici/lib/api/api-pipeline.js +252 -0
- package/dist/node_modules/undici/lib/api/api-request.js +214 -0
- package/dist/node_modules/undici/lib/api/api-stream.js +209 -0
- package/dist/node_modules/undici/lib/api/api-upgrade.js +111 -0
- package/dist/node_modules/undici/lib/api/index.js +7 -0
- package/dist/node_modules/undici/lib/api/readable.js +580 -0
- package/dist/node_modules/undici/lib/cache/memory-cache-store.js +234 -0
- package/dist/node_modules/undici/lib/cache/sqlite-cache-store.js +461 -0
- package/dist/node_modules/undici/lib/core/connect.js +137 -0
- package/dist/node_modules/undici/lib/core/constants.js +143 -0
- package/dist/node_modules/undici/lib/core/diagnostics.js +227 -0
- package/dist/node_modules/undici/lib/core/errors.js +477 -0
- package/dist/node_modules/undici/lib/core/request.js +438 -0
- package/dist/node_modules/undici/lib/core/socks5-client.js +407 -0
- package/dist/node_modules/undici/lib/core/socks5-utils.js +203 -0
- package/dist/node_modules/undici/lib/core/symbols.js +75 -0
- package/dist/node_modules/undici/lib/core/tree.js +160 -0
- package/dist/node_modules/undici/lib/core/util.js +992 -0
- package/dist/node_modules/undici/lib/dispatcher/agent.js +158 -0
- package/dist/node_modules/undici/lib/dispatcher/balanced-pool.js +219 -0
- package/dist/node_modules/undici/lib/dispatcher/client-h1.js +1610 -0
- package/dist/node_modules/undici/lib/dispatcher/client-h2.js +995 -0
- package/dist/node_modules/undici/lib/dispatcher/client.js +659 -0
- package/dist/node_modules/undici/lib/dispatcher/dispatcher-base.js +165 -0
- package/dist/node_modules/undici/lib/dispatcher/dispatcher.js +48 -0
- package/dist/node_modules/undici/lib/dispatcher/env-http-proxy-agent.js +146 -0
- package/dist/node_modules/undici/lib/dispatcher/fixed-queue.js +135 -0
- package/dist/node_modules/undici/lib/dispatcher/h2c-client.js +51 -0
- package/dist/node_modules/undici/lib/dispatcher/pool-base.js +214 -0
- package/dist/node_modules/undici/lib/dispatcher/pool.js +118 -0
- package/dist/node_modules/undici/lib/dispatcher/proxy-agent.js +318 -0
- package/dist/node_modules/undici/lib/dispatcher/retry-agent.js +35 -0
- package/dist/node_modules/undici/lib/dispatcher/round-robin-pool.js +137 -0
- package/dist/node_modules/undici/lib/dispatcher/socks5-proxy-agent.js +249 -0
- package/dist/node_modules/undici/lib/encoding/index.js +33 -0
- package/dist/node_modules/undici/lib/global.js +50 -0
- package/dist/node_modules/undici/lib/handler/cache-handler.js +578 -0
- package/dist/node_modules/undici/lib/handler/cache-revalidation-handler.js +124 -0
- package/dist/node_modules/undici/lib/handler/decorator-handler.js +67 -0
- package/dist/node_modules/undici/lib/handler/deduplication-handler.js +460 -0
- package/dist/node_modules/undici/lib/handler/redirect-handler.js +238 -0
- package/dist/node_modules/undici/lib/handler/retry-handler.js +394 -0
- package/dist/node_modules/undici/lib/handler/unwrap-handler.js +100 -0
- package/dist/node_modules/undici/lib/handler/wrap-handler.js +105 -0
- package/dist/node_modules/undici/lib/interceptor/cache.js +495 -0
- package/dist/node_modules/undici/lib/interceptor/decompress.js +259 -0
- package/dist/node_modules/undici/lib/interceptor/deduplicate.js +117 -0
- package/dist/node_modules/undici/lib/interceptor/dns.js +571 -0
- package/dist/node_modules/undici/lib/interceptor/dump.js +112 -0
- package/dist/node_modules/undici/lib/interceptor/redirect.js +21 -0
- package/dist/node_modules/undici/lib/interceptor/response-error.js +95 -0
- package/dist/node_modules/undici/lib/interceptor/retry.js +19 -0
- package/dist/node_modules/undici/lib/llhttp/.gitkeep +0 -0
- package/dist/node_modules/undici/lib/llhttp/constants.d.ts +195 -0
- package/dist/node_modules/undici/lib/llhttp/constants.js +531 -0
- package/dist/node_modules/undici/lib/llhttp/llhttp-wasm.js +15 -0
- package/dist/node_modules/undici/lib/llhttp/llhttp_simd-wasm.js +15 -0
- package/dist/node_modules/undici/lib/llhttp/utils.d.ts +2 -0
- package/dist/node_modules/undici/lib/llhttp/utils.js +12 -0
- package/dist/node_modules/undici/lib/mock/mock-agent.js +232 -0
- package/dist/node_modules/undici/lib/mock/mock-call-history.js +248 -0
- package/dist/node_modules/undici/lib/mock/mock-client.js +68 -0
- package/dist/node_modules/undici/lib/mock/mock-errors.js +29 -0
- package/dist/node_modules/undici/lib/mock/mock-interceptor.js +209 -0
- package/dist/node_modules/undici/lib/mock/mock-pool.js +68 -0
- package/dist/node_modules/undici/lib/mock/mock-symbols.js +32 -0
- package/dist/node_modules/undici/lib/mock/mock-utils.js +486 -0
- package/dist/node_modules/undici/lib/mock/pending-interceptors-formatter.js +43 -0
- package/dist/node_modules/undici/lib/mock/snapshot-agent.js +353 -0
- package/dist/node_modules/undici/lib/mock/snapshot-recorder.js +588 -0
- package/dist/node_modules/undici/lib/mock/snapshot-utils.js +158 -0
- package/dist/node_modules/undici/lib/util/cache.js +407 -0
- package/dist/node_modules/undici/lib/util/date.js +653 -0
- package/dist/node_modules/undici/lib/util/promise.js +28 -0
- package/dist/node_modules/undici/lib/util/runtime-features.js +124 -0
- package/dist/node_modules/undici/lib/util/stats.js +32 -0
- package/dist/node_modules/undici/lib/util/timers.js +425 -0
- package/dist/node_modules/undici/lib/web/cache/cache.js +864 -0
- package/dist/node_modules/undici/lib/web/cache/cachestorage.js +152 -0
- package/dist/node_modules/undici/lib/web/cache/util.js +45 -0
- package/dist/node_modules/undici/lib/web/cookies/constants.js +12 -0
- package/dist/node_modules/undici/lib/web/cookies/index.js +199 -0
- package/dist/node_modules/undici/lib/web/cookies/parse.js +322 -0
- package/dist/node_modules/undici/lib/web/cookies/util.js +282 -0
- package/dist/node_modules/undici/lib/web/eventsource/eventsource-stream.js +399 -0
- package/dist/node_modules/undici/lib/web/eventsource/eventsource.js +501 -0
- package/dist/node_modules/undici/lib/web/eventsource/util.js +29 -0
- package/dist/node_modules/undici/lib/web/fetch/LICENSE +21 -0
- package/dist/node_modules/undici/lib/web/fetch/body.js +509 -0
- package/dist/node_modules/undici/lib/web/fetch/constants.js +131 -0
- package/dist/node_modules/undici/lib/web/fetch/data-url.js +596 -0
- package/dist/node_modules/undici/lib/web/fetch/formdata-parser.js +575 -0
- package/dist/node_modules/undici/lib/web/fetch/formdata.js +259 -0
- package/dist/node_modules/undici/lib/web/fetch/global.js +40 -0
- package/dist/node_modules/undici/lib/web/fetch/headers.js +719 -0
- package/dist/node_modules/undici/lib/web/fetch/index.js +2397 -0
- package/dist/node_modules/undici/lib/web/fetch/request.js +1115 -0
- package/dist/node_modules/undici/lib/web/fetch/response.js +641 -0
- package/dist/node_modules/undici/lib/web/fetch/util.js +1520 -0
- package/dist/node_modules/undici/lib/web/infra/index.js +229 -0
- package/dist/node_modules/undici/lib/web/subresource-integrity/Readme.md +9 -0
- package/dist/node_modules/undici/lib/web/subresource-integrity/subresource-integrity.js +307 -0
- package/dist/node_modules/undici/lib/web/webidl/index.js +1006 -0
- package/dist/node_modules/undici/lib/web/websocket/connection.js +329 -0
- package/dist/node_modules/undici/lib/web/websocket/constants.js +126 -0
- package/dist/node_modules/undici/lib/web/websocket/events.js +331 -0
- package/dist/node_modules/undici/lib/web/websocket/frame.js +133 -0
- package/dist/node_modules/undici/lib/web/websocket/permessage-deflate.js +118 -0
- package/dist/node_modules/undici/lib/web/websocket/receiver.js +450 -0
- package/dist/node_modules/undici/lib/web/websocket/sender.js +109 -0
- package/dist/node_modules/undici/lib/web/websocket/stream/websocketerror.js +104 -0
- package/dist/node_modules/undici/lib/web/websocket/stream/websocketstream.js +497 -0
- package/dist/node_modules/undici/lib/web/websocket/util.js +347 -0
- package/dist/node_modules/undici/lib/web/websocket/websocket.js +751 -0
- package/dist/node_modules/undici/package.json +152 -0
- package/dist/node_modules/undici/scripts/strip-comments.js +10 -0
- package/dist/node_modules/undici/types/README.md +6 -0
- package/dist/node_modules/undici/types/agent.d.ts +32 -0
- package/dist/node_modules/undici/types/api.d.ts +43 -0
- package/dist/node_modules/undici/types/balanced-pool.d.ts +30 -0
- package/dist/node_modules/undici/types/cache-interceptor.d.ts +179 -0
- package/dist/node_modules/undici/types/cache.d.ts +36 -0
- package/dist/node_modules/undici/types/client-stats.d.ts +15 -0
- package/dist/node_modules/undici/types/client.d.ts +123 -0
- package/dist/node_modules/undici/types/connector.d.ts +36 -0
- package/dist/node_modules/undici/types/content-type.d.ts +21 -0
- package/dist/node_modules/undici/types/cookies.d.ts +30 -0
- package/dist/node_modules/undici/types/diagnostics-channel.d.ts +74 -0
- package/dist/node_modules/undici/types/dispatcher.d.ts +273 -0
- package/dist/node_modules/undici/types/env-http-proxy-agent.d.ts +22 -0
- package/dist/node_modules/undici/types/errors.d.ts +177 -0
- package/dist/node_modules/undici/types/eventsource.d.ts +66 -0
- package/dist/node_modules/undici/types/fetch.d.ts +231 -0
- package/dist/node_modules/undici/types/formdata.d.ts +114 -0
- package/dist/node_modules/undici/types/global-dispatcher.d.ts +9 -0
- package/dist/node_modules/undici/types/global-origin.d.ts +7 -0
- package/dist/node_modules/undici/types/h2c-client.d.ts +73 -0
- package/dist/node_modules/undici/types/handlers.d.ts +14 -0
- package/dist/node_modules/undici/types/header.d.ts +160 -0
- package/dist/node_modules/undici/types/index.d.ts +91 -0
- package/dist/node_modules/undici/types/interceptors.d.ts +80 -0
- package/dist/node_modules/undici/types/mock-agent.d.ts +68 -0
- package/dist/node_modules/undici/types/mock-call-history.d.ts +111 -0
- package/dist/node_modules/undici/types/mock-client.d.ts +27 -0
- package/dist/node_modules/undici/types/mock-errors.d.ts +12 -0
- package/dist/node_modules/undici/types/mock-interceptor.d.ts +94 -0
- package/dist/node_modules/undici/types/mock-pool.d.ts +27 -0
- package/dist/node_modules/undici/types/patch.d.ts +29 -0
- package/dist/node_modules/undici/types/pool-stats.d.ts +19 -0
- package/dist/node_modules/undici/types/pool.d.ts +41 -0
- package/dist/node_modules/undici/types/proxy-agent.d.ts +29 -0
- package/dist/node_modules/undici/types/readable.d.ts +68 -0
- package/dist/node_modules/undici/types/retry-agent.d.ts +8 -0
- package/dist/node_modules/undici/types/retry-handler.d.ts +125 -0
- package/dist/node_modules/undici/types/round-robin-pool.d.ts +41 -0
- package/dist/node_modules/undici/types/snapshot-agent.d.ts +109 -0
- package/dist/node_modules/undici/types/socks5-proxy-agent.d.ts +25 -0
- package/dist/node_modules/undici/types/util.d.ts +18 -0
- package/dist/node_modules/undici/types/utility.d.ts +7 -0
- package/dist/node_modules/undici/types/webidl.d.ts +347 -0
- package/dist/node_modules/undici/types/websocket.d.ts +188 -0
- package/dist/server/collections/oidcStates.d.ts +10 -0
- package/dist/server/collections/oidcStates.js +96 -0
- package/dist/server/db-adapter.d.ts +25 -0
- package/dist/server/db-adapter.js +156 -0
- package/dist/server/service.js +11 -10
- package/package.json +2 -2
- package/dist/server/cache-adapter.d.ts +0 -33
- package/dist/server/cache-adapter.js +0 -159
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This file is part of the NocoBase (R) project.
|
|
3
|
+
* Copyright (c) 2020-2024 NocoBase Co., Ltd.
|
|
4
|
+
* Authors: NocoBase Team.
|
|
5
|
+
*
|
|
6
|
+
* This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
|
|
7
|
+
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
var __defProp = Object.defineProperty;
|
|
11
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
12
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
13
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
14
|
+
var __export = (target, all) => {
|
|
15
|
+
for (var name in all)
|
|
16
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
17
|
+
};
|
|
18
|
+
var __copyProps = (to, from, except, desc) => {
|
|
19
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
20
|
+
for (let key of __getOwnPropNames(from))
|
|
21
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
22
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
23
|
+
}
|
|
24
|
+
return to;
|
|
25
|
+
};
|
|
26
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
27
|
+
var db_adapter_exports = {};
|
|
28
|
+
__export(db_adapter_exports, {
|
|
29
|
+
createDbAdapter: () => createDbAdapter
|
|
30
|
+
});
|
|
31
|
+
module.exports = __toCommonJS(db_adapter_exports);
|
|
32
|
+
function epochTime(date = Date.now()) {
|
|
33
|
+
return Math.floor(date / 1e3);
|
|
34
|
+
}
|
|
35
|
+
function createDbAdapter(app, collectionName = "oidcStates") {
|
|
36
|
+
return class DbAdapter {
|
|
37
|
+
model;
|
|
38
|
+
constructor(model) {
|
|
39
|
+
this.model = model;
|
|
40
|
+
}
|
|
41
|
+
get repo() {
|
|
42
|
+
return app.db.getRepository(collectionName);
|
|
43
|
+
}
|
|
44
|
+
isExpired(record) {
|
|
45
|
+
if (!(record == null ? void 0 : record.expiresAt)) {
|
|
46
|
+
return false;
|
|
47
|
+
}
|
|
48
|
+
const value = record.expiresAt instanceof Date ? record.expiresAt.getTime() : new Date(record.expiresAt).getTime();
|
|
49
|
+
return value <= Date.now();
|
|
50
|
+
}
|
|
51
|
+
async destroyExpired(record) {
|
|
52
|
+
if (!(record == null ? void 0 : record.id)) {
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
await this.repo.destroy({
|
|
56
|
+
filterByTk: record.id
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
async findRecord(filter) {
|
|
60
|
+
const record = await this.repo.findOne({
|
|
61
|
+
filter
|
|
62
|
+
});
|
|
63
|
+
if (!record) {
|
|
64
|
+
return void 0;
|
|
65
|
+
}
|
|
66
|
+
if (this.isExpired(record)) {
|
|
67
|
+
await this.destroyExpired(record);
|
|
68
|
+
return void 0;
|
|
69
|
+
}
|
|
70
|
+
return record;
|
|
71
|
+
}
|
|
72
|
+
async destroy(id) {
|
|
73
|
+
const record = await this.repo.findOne({
|
|
74
|
+
filter: {
|
|
75
|
+
model: this.model,
|
|
76
|
+
oidcId: id
|
|
77
|
+
}
|
|
78
|
+
});
|
|
79
|
+
if (!record) {
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
await this.repo.destroy({
|
|
83
|
+
filterByTk: record.get("id")
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
async consume(id) {
|
|
87
|
+
const record = await this.findRecord({
|
|
88
|
+
model: this.model,
|
|
89
|
+
oidcId: id
|
|
90
|
+
});
|
|
91
|
+
if (!record) {
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
const payload = {
|
|
95
|
+
...record.get("payload") || {},
|
|
96
|
+
consumed: epochTime()
|
|
97
|
+
};
|
|
98
|
+
await this.repo.update({
|
|
99
|
+
filterByTk: record.get("id"),
|
|
100
|
+
values: {
|
|
101
|
+
payload,
|
|
102
|
+
consumedAt: Math.floor(Date.now() / 1e3)
|
|
103
|
+
}
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
async find(id) {
|
|
107
|
+
const record = await this.findRecord({
|
|
108
|
+
model: this.model,
|
|
109
|
+
oidcId: id
|
|
110
|
+
});
|
|
111
|
+
return record == null ? void 0 : record.get("payload");
|
|
112
|
+
}
|
|
113
|
+
async findByUid(uid) {
|
|
114
|
+
const record = await this.findRecord({
|
|
115
|
+
model: this.model,
|
|
116
|
+
uid
|
|
117
|
+
});
|
|
118
|
+
return record == null ? void 0 : record.get("payload");
|
|
119
|
+
}
|
|
120
|
+
async findByUserCode(userCode) {
|
|
121
|
+
const record = await this.findRecord({
|
|
122
|
+
model: this.model,
|
|
123
|
+
userCode
|
|
124
|
+
});
|
|
125
|
+
return record == null ? void 0 : record.get("payload");
|
|
126
|
+
}
|
|
127
|
+
async upsert(id, payload, expiresIn) {
|
|
128
|
+
await this.repo.updateOrCreate({
|
|
129
|
+
filterKeys: ["model", "oidcId"],
|
|
130
|
+
values: {
|
|
131
|
+
model: this.model,
|
|
132
|
+
oidcId: id,
|
|
133
|
+
payload,
|
|
134
|
+
grantId: payload.grantId || null,
|
|
135
|
+
uid: payload.uid || null,
|
|
136
|
+
userCode: payload.userCode || null,
|
|
137
|
+
expiresAt: typeof expiresIn === "number" && Number.isFinite(expiresIn) ? Math.floor(Date.now() / 1e3) + expiresIn : null
|
|
138
|
+
}
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
async revokeByGrantId(grantId) {
|
|
142
|
+
if (!grantId) {
|
|
143
|
+
return;
|
|
144
|
+
}
|
|
145
|
+
await this.repo.destroy({
|
|
146
|
+
filter: {
|
|
147
|
+
grantId
|
|
148
|
+
}
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
};
|
|
152
|
+
}
|
|
153
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
154
|
+
0 && (module.exports = {
|
|
155
|
+
createDbAdapter
|
|
156
|
+
});
|
package/dist/server/service.js
CHANGED
|
@@ -44,8 +44,9 @@ var import_node_fs = __toESM(require("node:fs"));
|
|
|
44
44
|
var import_light_my_request = __toESM(require("light-my-request"));
|
|
45
45
|
var import_node_crypto = require("node:crypto");
|
|
46
46
|
var import_node_path = __toESM(require("node:path"));
|
|
47
|
-
var
|
|
48
|
-
var
|
|
47
|
+
var import_utils = require("@nocobase/utils");
|
|
48
|
+
var import_db_adapter = require("./db-adapter");
|
|
49
|
+
var import_utils2 = require("./utils");
|
|
49
50
|
let oidcModulePromise = null;
|
|
50
51
|
let joseModulePromise = null;
|
|
51
52
|
function getOidcModule() {
|
|
@@ -79,7 +80,7 @@ class IdpOauthService {
|
|
|
79
80
|
return process.env.APP_PUBLIC_ORIGIN || `${protocol}://${host}`;
|
|
80
81
|
}
|
|
81
82
|
getApiBasePath() {
|
|
82
|
-
return (0,
|
|
83
|
+
return (0, import_utils2.normalizeBasePath)(process.env.API_BASE_PATH || "/api");
|
|
83
84
|
}
|
|
84
85
|
getRequestPath(ctx) {
|
|
85
86
|
var _a, _b;
|
|
@@ -212,17 +213,17 @@ class IdpOauthService {
|
|
|
212
213
|
return void 0;
|
|
213
214
|
}
|
|
214
215
|
const normalizedPath = config.path.startsWith("/") ? config.path : `/${config.path}`;
|
|
215
|
-
return `${(0,
|
|
216
|
+
return `${(0, import_utils2.normalizeBasePath)(process.env.API_BASE_PATH || "/api")}${normalizedPath}`;
|
|
216
217
|
}
|
|
217
218
|
getRequestResourceConfig(ctx) {
|
|
218
|
-
const requestPath = (0,
|
|
219
|
+
const requestPath = (0, import_utils2.normalizeBasePath)(ctx.path || this.getRequestPath(ctx) || "/");
|
|
219
220
|
for (const config of this.resourceServers.values()) {
|
|
220
221
|
const resourcePath = this.getResourcePath(config);
|
|
221
222
|
if (!resourcePath) {
|
|
222
223
|
continue;
|
|
223
224
|
}
|
|
224
|
-
const normalizedResourcePath = (0,
|
|
225
|
-
const isRootResource = normalizedResourcePath === (0,
|
|
225
|
+
const normalizedResourcePath = (0, import_utils2.normalizeBasePath)(resourcePath);
|
|
226
|
+
const isRootResource = normalizedResourcePath === (0, import_utils2.normalizeBasePath)(`${this.getApiBasePath()}/`);
|
|
226
227
|
const matches = requestPath === normalizedResourcePath || requestPath.startsWith(`${normalizedResourcePath}/`) || isRootResource && requestPath.startsWith(`${this.getApiBasePath()}/`);
|
|
227
228
|
if (matches) {
|
|
228
229
|
return config;
|
|
@@ -235,7 +236,7 @@ class IdpOauthService {
|
|
|
235
236
|
return this.resourceJwks.get(provider.issuer);
|
|
236
237
|
}
|
|
237
238
|
const { createLocalJWKSet } = await getJoseModule();
|
|
238
|
-
const issuerPath = (0,
|
|
239
|
+
const issuerPath = (0, import_utils2.normalizeBasePath)(new URL(provider.issuer).pathname || "/");
|
|
239
240
|
const jwksPath = provider.pathFor("jwks");
|
|
240
241
|
const internalJwksPath = jwksPath === issuerPath ? "/" : jwksPath.startsWith(`${issuerPath}/`) ? jwksPath.slice(issuerPath.length) || "/" : jwksPath;
|
|
241
242
|
const response = await (0, import_light_my_request.default)(provider.callback(), {
|
|
@@ -267,7 +268,7 @@ class IdpOauthService {
|
|
|
267
268
|
};
|
|
268
269
|
}
|
|
269
270
|
getDefaultJwksPath(appName) {
|
|
270
|
-
return
|
|
271
|
+
return (0, import_utils.storagePathJoin)("apps", appName, "idp_oauth_jwks.json");
|
|
271
272
|
}
|
|
272
273
|
async getProviderSigningJwks(appName) {
|
|
273
274
|
const parseJwks = (value, source) => {
|
|
@@ -469,7 +470,7 @@ class IdpOauthService {
|
|
|
469
470
|
}
|
|
470
471
|
const jwks = await this.getProviderSigningJwks(appName);
|
|
471
472
|
return {
|
|
472
|
-
adapter: (0,
|
|
473
|
+
adapter: (0, import_db_adapter.createDbAdapter)(this.app, "oidcStates"),
|
|
473
474
|
clients: [],
|
|
474
475
|
scopes: this.getSupportedScopes(),
|
|
475
476
|
jwks,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nocobase/plugin-idp-oauth",
|
|
3
|
-
"version": "2.1.0-alpha.
|
|
3
|
+
"version": "2.1.0-alpha.19",
|
|
4
4
|
"main": "dist/server/index.js",
|
|
5
5
|
"displayName": "IdP: OAuth",
|
|
6
6
|
"displayName.zh-CN": "IdP: OAuth",
|
|
@@ -20,5 +20,5 @@
|
|
|
20
20
|
"keywords": [
|
|
21
21
|
"Authentication"
|
|
22
22
|
],
|
|
23
|
-
"gitHead": "
|
|
23
|
+
"gitHead": "3d13700360eac1c0f9dbf6a5f167ed396a294a3c"
|
|
24
24
|
}
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* This file is part of the NocoBase (R) project.
|
|
3
|
-
* Copyright (c) 2020-2024 NocoBase Co., Ltd.
|
|
4
|
-
* Authors: NocoBase Team.
|
|
5
|
-
*
|
|
6
|
-
* This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
|
|
7
|
-
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
|
-
*/
|
|
9
|
-
import type { Cache } from '@nocobase/cache';
|
|
10
|
-
type StoredPayload = Record<string, any> & {
|
|
11
|
-
__expiresAt?: number;
|
|
12
|
-
};
|
|
13
|
-
export declare function createCacheAdapter(cache: Cache, namespace: string): {
|
|
14
|
-
new (model: string): {
|
|
15
|
-
model: string;
|
|
16
|
-
key(id: string): string;
|
|
17
|
-
read(id: string): Promise<StoredPayload>;
|
|
18
|
-
destroy(id: string): Promise<void>;
|
|
19
|
-
consume(id: string): Promise<void>;
|
|
20
|
-
find(id: string): Promise<{
|
|
21
|
-
[x: string]: any;
|
|
22
|
-
}>;
|
|
23
|
-
findByUid(uid: string): Promise<{
|
|
24
|
-
[x: string]: any;
|
|
25
|
-
}>;
|
|
26
|
-
findByUserCode(userCode: string): Promise<{
|
|
27
|
-
[x: string]: any;
|
|
28
|
-
}>;
|
|
29
|
-
upsert(id: string, payload: Record<string, any>, expiresIn: number): Promise<void>;
|
|
30
|
-
revokeByGrantId(grantId: string): Promise<void>;
|
|
31
|
-
};
|
|
32
|
-
};
|
|
33
|
-
export {};
|
|
@@ -1,159 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* This file is part of the NocoBase (R) project.
|
|
3
|
-
* Copyright (c) 2020-2024 NocoBase Co., Ltd.
|
|
4
|
-
* Authors: NocoBase Team.
|
|
5
|
-
*
|
|
6
|
-
* This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
|
|
7
|
-
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
var __defProp = Object.defineProperty;
|
|
11
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
12
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
13
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
14
|
-
var __export = (target, all) => {
|
|
15
|
-
for (var name in all)
|
|
16
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
17
|
-
};
|
|
18
|
-
var __copyProps = (to, from, except, desc) => {
|
|
19
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
20
|
-
for (let key of __getOwnPropNames(from))
|
|
21
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
22
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
23
|
-
}
|
|
24
|
-
return to;
|
|
25
|
-
};
|
|
26
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
27
|
-
var cache_adapter_exports = {};
|
|
28
|
-
__export(cache_adapter_exports, {
|
|
29
|
-
createCacheAdapter: () => createCacheAdapter
|
|
30
|
-
});
|
|
31
|
-
module.exports = __toCommonJS(cache_adapter_exports);
|
|
32
|
-
const grantable = /* @__PURE__ */ new Set([
|
|
33
|
-
"AccessToken",
|
|
34
|
-
"AuthorizationCode",
|
|
35
|
-
"RefreshToken",
|
|
36
|
-
"DeviceCode",
|
|
37
|
-
"BackchannelAuthenticationRequest"
|
|
38
|
-
]);
|
|
39
|
-
function epochTime(date = Date.now()) {
|
|
40
|
-
return Math.floor(date / 1e3);
|
|
41
|
-
}
|
|
42
|
-
function createCacheAdapter(cache, namespace) {
|
|
43
|
-
const keyFor = (model, id) => `${namespace}:${model}:${id}`;
|
|
44
|
-
const grantKeyFor = (grantId) => `${namespace}:grant:${grantId}`;
|
|
45
|
-
const sessionUidKeyFor = (uid) => `${namespace}:sessionUid:${uid}`;
|
|
46
|
-
const userCodeKeyFor = (userCode) => `${namespace}:userCode:${userCode}`;
|
|
47
|
-
const normalize = (payload) => {
|
|
48
|
-
if (!payload) {
|
|
49
|
-
return void 0;
|
|
50
|
-
}
|
|
51
|
-
if (payload.__expiresAt && payload.__expiresAt <= Date.now()) {
|
|
52
|
-
return void 0;
|
|
53
|
-
}
|
|
54
|
-
const { __expiresAt, ...data } = payload;
|
|
55
|
-
return data;
|
|
56
|
-
};
|
|
57
|
-
const getRemainingTtl = (payload) => {
|
|
58
|
-
if (!(payload == null ? void 0 : payload.__expiresAt)) {
|
|
59
|
-
return void 0;
|
|
60
|
-
}
|
|
61
|
-
const ttl = payload.__expiresAt - Date.now();
|
|
62
|
-
return ttl > 0 ? ttl : void 0;
|
|
63
|
-
};
|
|
64
|
-
return class CacheAdapter {
|
|
65
|
-
model;
|
|
66
|
-
constructor(model) {
|
|
67
|
-
this.model = model;
|
|
68
|
-
}
|
|
69
|
-
key(id) {
|
|
70
|
-
return keyFor(this.model, id);
|
|
71
|
-
}
|
|
72
|
-
async read(id) {
|
|
73
|
-
const payload = await cache.get(this.key(id));
|
|
74
|
-
if (!payload) {
|
|
75
|
-
return void 0;
|
|
76
|
-
}
|
|
77
|
-
if (payload.__expiresAt && payload.__expiresAt <= Date.now()) {
|
|
78
|
-
await this.destroy(id);
|
|
79
|
-
return void 0;
|
|
80
|
-
}
|
|
81
|
-
return payload;
|
|
82
|
-
}
|
|
83
|
-
async destroy(id) {
|
|
84
|
-
const payload = await cache.get(this.key(id));
|
|
85
|
-
await cache.del(this.key(id));
|
|
86
|
-
if ((payload == null ? void 0 : payload.uid) && this.model === "Session") {
|
|
87
|
-
await cache.del(sessionUidKeyFor(payload.uid));
|
|
88
|
-
}
|
|
89
|
-
if (payload == null ? void 0 : payload.userCode) {
|
|
90
|
-
await cache.del(userCodeKeyFor(payload.userCode));
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
async consume(id) {
|
|
94
|
-
const payload = await this.read(id);
|
|
95
|
-
if (!payload) {
|
|
96
|
-
return;
|
|
97
|
-
}
|
|
98
|
-
payload.consumed = epochTime();
|
|
99
|
-
await cache.set(this.key(id), payload, getRemainingTtl(payload));
|
|
100
|
-
}
|
|
101
|
-
async find(id) {
|
|
102
|
-
return normalize(await this.read(id));
|
|
103
|
-
}
|
|
104
|
-
async findByUid(uid) {
|
|
105
|
-
const id = await cache.get(sessionUidKeyFor(uid));
|
|
106
|
-
if (!id) {
|
|
107
|
-
return void 0;
|
|
108
|
-
}
|
|
109
|
-
return this.find(id);
|
|
110
|
-
}
|
|
111
|
-
async findByUserCode(userCode) {
|
|
112
|
-
const id = await cache.get(userCodeKeyFor(userCode));
|
|
113
|
-
if (!id) {
|
|
114
|
-
return void 0;
|
|
115
|
-
}
|
|
116
|
-
return this.find(id);
|
|
117
|
-
}
|
|
118
|
-
async upsert(id, payload, expiresIn) {
|
|
119
|
-
const ttl = expiresIn * 1e3;
|
|
120
|
-
const stored = {
|
|
121
|
-
...payload,
|
|
122
|
-
__expiresAt: Date.now() + ttl
|
|
123
|
-
};
|
|
124
|
-
if (this.model === "Session" && payload.uid) {
|
|
125
|
-
await cache.set(sessionUidKeyFor(payload.uid), id, ttl);
|
|
126
|
-
}
|
|
127
|
-
if (grantable.has(this.model) && payload.grantId) {
|
|
128
|
-
const grantKey = grantKeyFor(payload.grantId);
|
|
129
|
-
const grant = (await cache.get(grantKey) || []).filter(Boolean);
|
|
130
|
-
if (!grant.includes(this.key(id))) {
|
|
131
|
-
grant.push(this.key(id));
|
|
132
|
-
}
|
|
133
|
-
await cache.set(grantKey, grant, ttl);
|
|
134
|
-
}
|
|
135
|
-
if (payload.userCode) {
|
|
136
|
-
await cache.set(userCodeKeyFor(payload.userCode), id, ttl);
|
|
137
|
-
}
|
|
138
|
-
await cache.set(this.key(id), stored, ttl);
|
|
139
|
-
}
|
|
140
|
-
async revokeByGrantId(grantId) {
|
|
141
|
-
const grantKey = grantKeyFor(grantId);
|
|
142
|
-
const grant = await cache.get(grantKey);
|
|
143
|
-
if (!(grant == null ? void 0 : grant.length)) {
|
|
144
|
-
return;
|
|
145
|
-
}
|
|
146
|
-
await Promise.all(
|
|
147
|
-
grant.map((tokenKey) => {
|
|
148
|
-
const id = tokenKey.slice(this.key("").length);
|
|
149
|
-
return this.destroy(id);
|
|
150
|
-
})
|
|
151
|
-
);
|
|
152
|
-
await cache.del(grantKey);
|
|
153
|
-
}
|
|
154
|
-
};
|
|
155
|
-
}
|
|
156
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
157
|
-
0 && (module.exports = {
|
|
158
|
-
createCacheAdapter
|
|
159
|
-
});
|