@eaera-com/cms-sdk 0.1.101 → 0.1.102
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/dist/chunks/{_shared-Dyz_Ya9z.js → _shared-DWYblQqx.js} +6 -1
- package/dist/chunks/_txn-DmQZNq48.js +99 -0
- package/dist/chunks/{connection--KUpmDbP.js → connection-DprBIh4D.js} +0 -10
- package/dist/common/constants/oauth.constant.d.ts +26 -0
- package/dist/common/constants/oauth.constant.d.ts.map +1 -0
- package/dist/nuxt.d.ts +5 -0
- package/dist/nuxt.d.ts.map +1 -1
- package/dist/nuxt.js +4 -0
- package/dist/runtime/plugin.js +6 -1
- package/dist/server/ai/qwenpaw/chat/stop.post.js +1 -1
- package/dist/server/ai/qwenpaw/chat.post.js +1 -1
- package/dist/server/ai/qwenpaw/chats-id.delete.js +1 -1
- package/dist/server/ai/qwenpaw/chats.get.js +1 -1
- package/dist/server/ai/qwenpaw/history.get.js +1 -1
- package/dist/server/ai/qwenpaw/session.get.js +1 -1
- package/dist/server/ai/qwenpaw/session.post.js +1 -1
- package/dist/server/ai/qwenpaw/upload.post.js +1 -1
- package/dist/server/auth/cbs-callback.post.js +3 -3
- package/dist/server/auth/cbs-start.post.js +1 -1
- package/dist/server/auth/idp-callback.get.js +3 -3
- package/dist/server/auth/idp-link-callback.get.js +1 -1
- package/dist/server/auth/idp-link-start.get.js +1 -1
- package/dist/server/auth/idp-link.post.js +1 -1
- package/dist/server/auth/idp-login.get.js +1 -1
- package/dist/server/auth/idp-me.get.js +1 -1
- package/dist/server/auth/idp-unlink.delete.js +1 -1
- package/dist/server/auth/login.post.js +3 -3
- package/dist/server/auth/logout.post.js +1 -1
- package/dist/server/auth/refresh.post.js +18 -3
- package/dist/server/authz/portal-access.get.js +1 -1
- package/dist/server/oauth/callback.get.js +53 -0
- package/dist/server/oauth/start.get.js +46 -0
- package/package.json +1 -1
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { a as COOKIE_DEFAULTS } from './storage.constant-CVWam5ls.js';
|
|
2
|
+
import { getRequestURL } from 'h3';
|
|
2
3
|
import { useRuntimeConfig } from '#imports';
|
|
3
4
|
|
|
4
5
|
const TOKEN_COOKIE_OPTIONS = {
|
|
@@ -8,6 +9,10 @@ const TOKEN_COOKIE_OPTIONS = {
|
|
|
8
9
|
path: COOKIE_DEFAULTS.PATH,
|
|
9
10
|
maxAge: COOKIE_DEFAULTS.MAX_AGE_SECONDS
|
|
10
11
|
};
|
|
12
|
+
function tokenCookieOptions(event) {
|
|
13
|
+
const secure = new URL(getRequestURL(event)).protocol === "https:";
|
|
14
|
+
return { ...TOKEN_COOKIE_OPTIONS, secure };
|
|
15
|
+
}
|
|
11
16
|
function readSdkConfig(event) {
|
|
12
17
|
const config = useRuntimeConfig(event);
|
|
13
18
|
const pub = config?.public ?? {};
|
|
@@ -22,4 +27,4 @@ function readSdkConfig(event) {
|
|
|
22
27
|
};
|
|
23
28
|
}
|
|
24
29
|
|
|
25
|
-
export { TOKEN_COOKIE_OPTIONS as T, readSdkConfig as r };
|
|
30
|
+
export { TOKEN_COOKIE_OPTIONS as T, readSdkConfig as r, tokenCookieOptions as t };
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import { timingSafeEqual, randomBytes, createHash } from 'node:crypto';
|
|
2
|
+
import { parseCookies, setCookie } from 'h3';
|
|
3
|
+
|
|
4
|
+
const OAUTH_PROXY_PATH = {
|
|
5
|
+
/** GET — CMS code callback (state check + code exchange). Must match the
|
|
6
|
+
* route the Nuxt module registers in `nuxt.ts` (SERVER_HANDLERS). */
|
|
7
|
+
CALLBACK: "/api/cms/oauth/callback"
|
|
8
|
+
};
|
|
9
|
+
const OAUTH_TXN_COOKIE = "cms_oauth_txn";
|
|
10
|
+
const OAUTH_TXN_TTL_MS = 10 * 60 * 1e3;
|
|
11
|
+
const OAUTH_TXN_MAX_ENTRIES = 1e3;
|
|
12
|
+
const OAUTH_GRANT_AUTHORIZATION_CODE = "authorization_code";
|
|
13
|
+
const OAUTH_PKCE_METHOD = "S256";
|
|
14
|
+
|
|
15
|
+
const GLOBAL_KEY = "__cms_sdk_oauth_txns__";
|
|
16
|
+
function store() {
|
|
17
|
+
const g = globalThis;
|
|
18
|
+
g[GLOBAL_KEY] ??= { txns: /* @__PURE__ */ new Map(), byState: /* @__PURE__ */ new Map() };
|
|
19
|
+
return g[GLOBAL_KEY];
|
|
20
|
+
}
|
|
21
|
+
function prune() {
|
|
22
|
+
const s = store();
|
|
23
|
+
const now = Date.now();
|
|
24
|
+
for (const [id, txn] of s.txns) {
|
|
25
|
+
if (now - txn.createdAt > OAUTH_TXN_TTL_MS) {
|
|
26
|
+
s.txns.delete(id);
|
|
27
|
+
s.byState.delete(txn.state);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
while (s.txns.size > OAUTH_TXN_MAX_ENTRIES) {
|
|
31
|
+
const oldest = s.txns.keys().next().value;
|
|
32
|
+
if (!oldest) break;
|
|
33
|
+
const txn = s.txns.get(oldest);
|
|
34
|
+
s.txns.delete(oldest);
|
|
35
|
+
if (txn) s.byState.delete(txn.state);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
function base64url(bytes) {
|
|
39
|
+
return bytes.toString("base64url");
|
|
40
|
+
}
|
|
41
|
+
function createPkce() {
|
|
42
|
+
return {
|
|
43
|
+
state: base64url(randomBytes(32)),
|
|
44
|
+
verifier: base64url(randomBytes(64)),
|
|
45
|
+
challenge: ""
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
function codeChallenge(verifier) {
|
|
49
|
+
return base64url(createHash("sha256").update(verifier).digest());
|
|
50
|
+
}
|
|
51
|
+
function saveTransaction(txn) {
|
|
52
|
+
prune();
|
|
53
|
+
const id = base64url(randomBytes(24));
|
|
54
|
+
const s = store();
|
|
55
|
+
s.txns.set(id, txn);
|
|
56
|
+
s.byState.set(txn.state, id);
|
|
57
|
+
return id;
|
|
58
|
+
}
|
|
59
|
+
function consumeTransaction(event, state) {
|
|
60
|
+
const s = store();
|
|
61
|
+
const id = s.byState.get(state);
|
|
62
|
+
if (!id) return null;
|
|
63
|
+
const cookie = parseCookies(event)[OAUTH_TXN_COOKIE];
|
|
64
|
+
if (!cookie || !safeEqual(cookie, id)) return null;
|
|
65
|
+
const txn = s.txns.get(id);
|
|
66
|
+
if (!txn) return null;
|
|
67
|
+
s.txns.delete(id);
|
|
68
|
+
s.byState.delete(state);
|
|
69
|
+
if (Date.now() - txn.createdAt > OAUTH_TXN_TTL_MS) return null;
|
|
70
|
+
return txn;
|
|
71
|
+
}
|
|
72
|
+
function clearTransactionCookie(event) {
|
|
73
|
+
setCookie(event, OAUTH_TXN_COOKIE, "", {
|
|
74
|
+
httpOnly: true,
|
|
75
|
+
sameSite: "lax",
|
|
76
|
+
path: "/",
|
|
77
|
+
maxAge: 0
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
function setTransactionCookie(event, txnId) {
|
|
81
|
+
setCookie(event, OAUTH_TXN_COOKIE, txnId, {
|
|
82
|
+
httpOnly: true,
|
|
83
|
+
sameSite: "lax",
|
|
84
|
+
path: "/",
|
|
85
|
+
maxAge: Math.floor(OAUTH_TXN_TTL_MS / 1e3)
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
const PKCE_METHOD = OAUTH_PKCE_METHOD;
|
|
89
|
+
function safeEqual(a, b) {
|
|
90
|
+
const bufA = Buffer.from(a);
|
|
91
|
+
const bufB = Buffer.from(b);
|
|
92
|
+
if (bufA.length !== bufB.length) return false;
|
|
93
|
+
return timingSafeEqual(bufA, bufB);
|
|
94
|
+
}
|
|
95
|
+
function safeReturnPath(value) {
|
|
96
|
+
return value && value.startsWith("/") && !value.startsWith("//") ? value : "/";
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
export { OAUTH_GRANT_AUTHORIZATION_CODE as O, PKCE_METHOD as P, clearTransactionCookie as a, createPkce as b, consumeTransaction as c, saveTransaction as d, setTransactionCookie as e, OAUTH_PROXY_PATH as f, codeChallenge as g, safeReturnPath as s };
|
|
@@ -27,11 +27,6 @@ const setQwenpawSessionCookies = (event, connection) => {
|
|
|
27
27
|
path: "/",
|
|
28
28
|
maxAge: QWENPAW_COOKIE_MAX_AGE
|
|
29
29
|
};
|
|
30
|
-
console.log("[qwenpaw] exchange saved connection →", {
|
|
31
|
-
agentId: connection.agentId,
|
|
32
|
-
agentIdIsConstant: connection.agentId === QWENPAW_DEFAULT_AGENT_ID,
|
|
33
|
-
baseUrl: connection.baseUrl
|
|
34
|
-
});
|
|
35
30
|
setCookie(event, QWENPAW_COOKIE_BASE_URL, connection.baseUrl, common);
|
|
36
31
|
};
|
|
37
32
|
const readCookieValue = (event, name) => {
|
|
@@ -44,11 +39,6 @@ const resolveQwenpawConnection = (event, overrides = {}) => {
|
|
|
44
39
|
baseUrl: overrides.baseUrl || readCookieValue(event, QWENPAW_COOKIE_BASE_URL) || config.baseUrl,
|
|
45
40
|
agentId: QWENPAW_DEFAULT_AGENT_ID
|
|
46
41
|
};
|
|
47
|
-
console.log("[qwenpaw] resolveQwenpawConnection →", {
|
|
48
|
-
agentId: resolved.agentId,
|
|
49
|
-
source: overrides.baseUrl ? "override" : readCookieValue(event, QWENPAW_COOKIE_BASE_URL) ? "cookie" : "runtimeConfig",
|
|
50
|
-
baseUrl: resolved.baseUrl
|
|
51
|
-
});
|
|
52
42
|
return resolved;
|
|
53
43
|
};
|
|
54
44
|
const hasQwenpawConnection = (event) => Boolean(resolveQwenpawConnection(event).baseUrl);
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Central-login OAuth constants (FEAT-014 portal integration contract).
|
|
3
|
+
*
|
|
4
|
+
* The portal BFF owns state + PKCE; the browser only ever sees the
|
|
5
|
+
* authorize redirect and the code/state echo on the callback. Secrets and
|
|
6
|
+
* verifiers stay server-side.
|
|
7
|
+
*/
|
|
8
|
+
export declare const OAUTH_PROXY_PATH: {
|
|
9
|
+
/** GET — starts the flow (302 to the CMS authorize URL). Must match the
|
|
10
|
+
* route the Nuxt module registers in `nuxt.ts` (SERVER_HANDLERS). */
|
|
11
|
+
readonly START: "/api/cms/oauth/start";
|
|
12
|
+
/** GET — CMS code callback (state check + code exchange). Must match the
|
|
13
|
+
* route the Nuxt module registers in `nuxt.ts` (SERVER_HANDLERS). */
|
|
14
|
+
readonly CALLBACK: "/api/cms/oauth/callback";
|
|
15
|
+
};
|
|
16
|
+
/** Browser-correlation cookie holding the local transaction id. */
|
|
17
|
+
export declare const OAUTH_TXN_COOKIE = "cms_oauth_txn";
|
|
18
|
+
/** Transaction TTL — must cover the whole login round-trip. */
|
|
19
|
+
export declare const OAUTH_TXN_TTL_MS: number;
|
|
20
|
+
/** Prune threshold — keep the in-memory map bounded. */
|
|
21
|
+
export declare const OAUTH_TXN_MAX_ENTRIES = 1000;
|
|
22
|
+
/** Token endpoint grant used for the code exchange. */
|
|
23
|
+
export declare const OAUTH_GRANT_AUTHORIZATION_CODE = "authorization_code";
|
|
24
|
+
/** PKCE method required by the CMS (S256, 43-char challenge, no padding). */
|
|
25
|
+
export declare const OAUTH_PKCE_METHOD = "S256";
|
|
26
|
+
//# sourceMappingURL=oauth.constant.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"oauth.constant.d.ts","sourceRoot":"","sources":["../../../src/common/constants/oauth.constant.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,eAAO,MAAM,gBAAgB;IAC3B;0EACsE;;IAEtE;0EACsE;;CAE9D,CAAC;AAEX,mEAAmE;AACnE,eAAO,MAAM,gBAAgB,kBAAkB,CAAC;AAEhD,+DAA+D;AAC/D,eAAO,MAAM,gBAAgB,QAAiB,CAAC;AAE/C,wDAAwD;AACxD,eAAO,MAAM,qBAAqB,OAAO,CAAC;AAE1C,uDAAuD;AACvD,eAAO,MAAM,8BAA8B,uBAAuB,CAAC;AAEnE,6EAA6E;AAC7E,eAAO,MAAM,iBAAiB,SAAS,CAAC"}
|
package/dist/nuxt.d.ts
CHANGED
|
@@ -7,6 +7,11 @@ export interface IModuleOptions {
|
|
|
7
7
|
*/
|
|
8
8
|
endpoints?: Record<string, string>;
|
|
9
9
|
clientId?: string;
|
|
10
|
+
/**
|
|
11
|
+
* OAuth scope requested by the central-login flow
|
|
12
|
+
* (`/api/cms/oauth/start`). Default 'read'.
|
|
13
|
+
*/
|
|
14
|
+
oauthScope?: string;
|
|
10
15
|
/** Storage backend name. Default 'cookie'. */
|
|
11
16
|
storage?: StorageName;
|
|
12
17
|
/** Use fake data until the backend is ready. Default false. */
|
package/dist/nuxt.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"nuxt.d.ts","sourceRoot":"","sources":["../src/nuxt.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,kCAAkC,CAAC;AACtF,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,qCAAqC,CAAC;AAEvE,MAAM,WAAW,cAAc;IAC7B;;;OAGG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACnC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,8CAA8C;IAC9C,OAAO,CAAC,EAAE,WAAW,CAAC;IACtB,+DAA+D;IAC/D,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,wFAAwF;IACxF,cAAc,CAAC,EAAE,cAAc,CAAC;IAChC,kFAAkF;IAClF,aAAa,CAAC,EAAE,aAAa,CAAC;IAC9B;;;;;OAKG;IACH,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAC;IACpB;;;OAGG;IACH,UAAU,CAAC,EAAE,OAAO,CAAC;CACtB;
|
|
1
|
+
{"version":3,"file":"nuxt.d.ts","sourceRoot":"","sources":["../src/nuxt.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,kCAAkC,CAAC;AACtF,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,qCAAqC,CAAC;AAEvE,MAAM,WAAW,cAAc;IAC7B;;;OAGG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACnC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB;;;OAGG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,8CAA8C;IAC9C,OAAO,CAAC,EAAE,WAAW,CAAC;IACtB,+DAA+D;IAC/D,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,wFAAwF;IACxF,cAAc,CAAC,EAAE,cAAc,CAAC;IAChC,kFAAkF;IAClF,aAAa,CAAC,EAAE,aAAa,CAAC;IAC9B;;;;;OAKG;IACH,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAC;IACpB;;;OAGG;IACH,UAAU,CAAC,EAAE,OAAO,CAAC;CACtB;AA+BD;;;;;;;;;;;;;GAaG;;AACH,wBA4CG"}
|
package/dist/nuxt.js
CHANGED
|
@@ -6,6 +6,8 @@ const SERVER_HANDLERS = [
|
|
|
6
6
|
["/api/cms/login", "server/auth/login.post.js"],
|
|
7
7
|
["/api/cms/logout", "server/auth/logout.post.js"],
|
|
8
8
|
["/api/cms/refresh", "server/auth/refresh.post.js"],
|
|
9
|
+
["/api/cms/oauth/start", "server/oauth/start.get.js"],
|
|
10
|
+
["/api/cms/oauth/callback", "server/oauth/callback.get.js"],
|
|
9
11
|
["/api/cms/cbs-start", "server/auth/cbs-start.post.js"],
|
|
10
12
|
["/api/cms/cbs-callback", "server/auth/cbs-callback.post.js"],
|
|
11
13
|
["/api/cms/idp-login", "server/auth/idp-login.get.js"],
|
|
@@ -35,6 +37,7 @@ const nuxt = defineNuxtModule({
|
|
|
35
37
|
defaults: {
|
|
36
38
|
endpoints: { cms: "cmsUrl", report: "reportUrl", poolTrading: "poolTradingUrl" },
|
|
37
39
|
clientId: "clientId",
|
|
40
|
+
oauthScope: "read",
|
|
38
41
|
storage: "cookie",
|
|
39
42
|
mock: false,
|
|
40
43
|
wsTopics: [],
|
|
@@ -45,6 +48,7 @@ const nuxt = defineNuxtModule({
|
|
|
45
48
|
const { resolve } = createResolver(import.meta.url);
|
|
46
49
|
nuxt.options.runtimeConfig.public ??= {};
|
|
47
50
|
nuxt.options.runtimeConfig.public.cmsSdkOptions = options;
|
|
51
|
+
nuxt.options.runtimeConfig.cmsClientSecret ??= "";
|
|
48
52
|
for (const [route, file] of SERVER_HANDLERS) {
|
|
49
53
|
addServerHandler({ route, handler: resolve(file) });
|
|
50
54
|
}
|
package/dist/runtime/plugin.js
CHANGED
|
@@ -2,6 +2,7 @@ import { createCmsSDK, createPersistPlugin, TOKEN_STORAGE_KEY, useAuthStore, use
|
|
|
2
2
|
import { $fetch } from 'ofetch';
|
|
3
3
|
import { watch } from 'vue';
|
|
4
4
|
import { defineNuxtPlugin, useRuntimeConfig, useCookie } from '#app';
|
|
5
|
+
import { getRequestURL } from 'h3';
|
|
5
6
|
|
|
6
7
|
function buildOpts(httpOnly) {
|
|
7
8
|
return httpOnly ? { httpOnly: true, secure: true, sameSite: "lax", path: "/" } : { secure: true, sameSite: "lax", path: "/" };
|
|
@@ -27,6 +28,10 @@ const TOKEN_COOKIE_OPTIONS = {
|
|
|
27
28
|
path: "/",
|
|
28
29
|
maxAge: 60 * 60 * 24 * 30
|
|
29
30
|
};
|
|
31
|
+
function tokenCookieOptions(event) {
|
|
32
|
+
const secure = new URL(getRequestURL(event)).protocol === "https:";
|
|
33
|
+
return { ...TOKEN_COOKIE_OPTIONS, secure };
|
|
34
|
+
}
|
|
30
35
|
|
|
31
36
|
const STORE_ATTACHMENTS = [
|
|
32
37
|
{ name: "auth", get: useAuthStore },
|
|
@@ -81,7 +86,7 @@ const plugin = defineNuxtPlugin(async (nuxtApp) => {
|
|
|
81
86
|
if (import.meta.server) {
|
|
82
87
|
const { setCookie, deleteCookie } = await import('h3');
|
|
83
88
|
const event = nuxtApp.ssrContext?.event;
|
|
84
|
-
if (token) setCookie(event, TOKEN_STORAGE_KEY, token,
|
|
89
|
+
if (token) setCookie(event, TOKEN_STORAGE_KEY, token, tokenCookieOptions(event));
|
|
85
90
|
else deleteCookie(event, TOKEN_STORAGE_KEY, { path: TOKEN_COOKIE_OPTIONS.path });
|
|
86
91
|
} else if (token) {
|
|
87
92
|
await $fetch("/api/cms/set-token", { method: "POST", body: { token } });
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { defineEventHandler, readBody, createError } from 'h3';
|
|
2
2
|
import { c as qwenpawStop, p as postConsoleChatError } from '../../../../chunks/client-Ac6qgpZ8.js';
|
|
3
3
|
import { c as QWENPAW_MAX_SESSION_ID_LENGTH } from '../../../../chunks/qwenpaw.constant-DHSj9A-0.js';
|
|
4
|
-
import { r as requireCmsSession, a as resolveFreshQwenpawConnection, b as resolveQwenpawServerConfig } from '../../../../chunks/connection
|
|
4
|
+
import { r as requireCmsSession, a as resolveFreshQwenpawConnection, b as resolveQwenpawServerConfig } from '../../../../chunks/connection-DprBIh4D.js';
|
|
5
5
|
|
|
6
6
|
const stop_post = defineEventHandler(async (event) => {
|
|
7
7
|
requireCmsSession(event);
|
|
@@ -2,7 +2,7 @@ import { Readable } from 'node:stream';
|
|
|
2
2
|
import { defineEventHandler, readBody, createError, setResponseStatus, setResponseHeader, sendStream } from 'h3';
|
|
3
3
|
import { q as qwenpawChat, p as postConsoleChatError } from '../../../chunks/client-Ac6qgpZ8.js';
|
|
4
4
|
import { Q as QWENPAW_MAX_MESSAGE_LENGTH, a as QWENPAW_MAX_FILES, b as QWENPAW_MAX_FILE_NAME_LENGTH, c as QWENPAW_MAX_SESSION_ID_LENGTH } from '../../../chunks/qwenpaw.constant-DHSj9A-0.js';
|
|
5
|
-
import { r as requireCmsSession, a as resolveFreshQwenpawConnection, b as resolveQwenpawServerConfig } from '../../../chunks/connection
|
|
5
|
+
import { r as requireCmsSession, a as resolveFreshQwenpawConnection, b as resolveQwenpawServerConfig } from '../../../chunks/connection-DprBIh4D.js';
|
|
6
6
|
|
|
7
7
|
const chat_post = defineEventHandler(async (event) => {
|
|
8
8
|
requireCmsSession(event);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { defineEventHandler, getRouterParam, createError } from 'h3';
|
|
2
2
|
import { d as deleteQwenpawChat } from '../../../chunks/chats-BjSS83OW.js';
|
|
3
|
-
import { r as requireCmsSession, a as resolveFreshQwenpawConnection } from '../../../chunks/connection
|
|
3
|
+
import { r as requireCmsSession, a as resolveFreshQwenpawConnection } from '../../../chunks/connection-DprBIh4D.js';
|
|
4
4
|
|
|
5
5
|
const chatsId_delete = defineEventHandler(async (event) => {
|
|
6
6
|
requireCmsSession(event);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { defineEventHandler } from 'h3';
|
|
2
2
|
import { l as listQwenpawChats, a as listQwenpawGroups } from '../../../chunks/chats-BjSS83OW.js';
|
|
3
3
|
import { d as QWENPAW_DEFAULT_AGENT_ID } from '../../../chunks/qwenpaw.constant-DHSj9A-0.js';
|
|
4
|
-
import { r as requireCmsSession, a as resolveFreshQwenpawConnection } from '../../../chunks/connection
|
|
4
|
+
import { r as requireCmsSession, a as resolveFreshQwenpawConnection } from '../../../chunks/connection-DprBIh4D.js';
|
|
5
5
|
|
|
6
6
|
const chats_get = defineEventHandler(async (event) => {
|
|
7
7
|
requireCmsSession(event);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { defineEventHandler, getQuery, createError } from 'h3';
|
|
2
2
|
import { f as fetchChatHistory } from '../../../chunks/chats-BjSS83OW.js';
|
|
3
|
-
import { r as requireCmsSession, a as resolveFreshQwenpawConnection } from '../../../chunks/connection
|
|
3
|
+
import { r as requireCmsSession, a as resolveFreshQwenpawConnection } from '../../../chunks/connection-DprBIh4D.js';
|
|
4
4
|
|
|
5
5
|
const history_get = defineEventHandler(async (event) => {
|
|
6
6
|
requireCmsSession(event);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { defineEventHandler } from 'h3';
|
|
2
|
-
import { r as requireCmsSession, c as resolveQwenpawConnection, h as hasQwenpawConnection } from '../../../chunks/connection
|
|
2
|
+
import { r as requireCmsSession, c as resolveQwenpawConnection, h as hasQwenpawConnection } from '../../../chunks/connection-DprBIh4D.js';
|
|
3
3
|
|
|
4
4
|
const session_get = defineEventHandler((event) => {
|
|
5
5
|
requireCmsSession(event);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { defineEventHandler } from 'h3';
|
|
2
|
-
import { r as requireCmsSession, e as exchangeQwenpawSession, d as handleExchangeError } from '../../../chunks/connection
|
|
2
|
+
import { r as requireCmsSession, e as exchangeQwenpawSession, d as handleExchangeError } from '../../../chunks/connection-DprBIh4D.js';
|
|
3
3
|
|
|
4
4
|
const session_post = defineEventHandler(async (event) => {
|
|
5
5
|
requireCmsSession(event);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { defineEventHandler, readMultipartFormData, createError } from 'h3';
|
|
2
2
|
import { d as qwenpawUpload, p as postConsoleChatError } from '../../../chunks/client-Ac6qgpZ8.js';
|
|
3
3
|
import { g as QWENPAW_MAX_UPLOAD_BYTES } from '../../../chunks/qwenpaw.constant-DHSj9A-0.js';
|
|
4
|
-
import { r as requireCmsSession, a as resolveFreshQwenpawConnection, b as resolveQwenpawServerConfig } from '../../../chunks/connection
|
|
4
|
+
import { r as requireCmsSession, a as resolveFreshQwenpawConnection, b as resolveQwenpawServerConfig } from '../../../chunks/connection-DprBIh4D.js';
|
|
5
5
|
|
|
6
6
|
const upload_post = defineEventHandler(async (event) => {
|
|
7
7
|
requireCmsSession(event);
|
|
@@ -2,7 +2,7 @@ import { defineEventHandler, createError, readBody, parseCookies, getRequestHead
|
|
|
2
2
|
import { $fetch } from 'ofetch';
|
|
3
3
|
import { a as AUTH_ENDPOINT } from '../../chunks/auth.constant-CnGo0q42.js';
|
|
4
4
|
import { b as HTTP_HEADER } from '../../chunks/http.constant-BzH5tJTG.js';
|
|
5
|
-
import { r as readSdkConfig,
|
|
5
|
+
import { r as readSdkConfig, t as tokenCookieOptions } from '../../chunks/_shared-DWYblQqx.js';
|
|
6
6
|
import { T as TOKEN_STORAGE_KEY, R as REFRESH_TOKEN_STORAGE_KEY } from '../../chunks/storage.constant-CVWam5ls.js';
|
|
7
7
|
|
|
8
8
|
const cbsCallback_post = defineEventHandler(async (event) => {
|
|
@@ -26,9 +26,9 @@ const cbsCallback_post = defineEventHandler(async (event) => {
|
|
|
26
26
|
const data = response._data ?? {};
|
|
27
27
|
const token = data.accessToken ?? data.access_token ?? "";
|
|
28
28
|
const refreshToken = data.refreshToken ?? data.refresh_token ?? "";
|
|
29
|
-
if (token) setCookie(event, TOKEN_STORAGE_KEY, token,
|
|
29
|
+
if (token) setCookie(event, TOKEN_STORAGE_KEY, token, tokenCookieOptions(event));
|
|
30
30
|
if (refreshToken)
|
|
31
|
-
setCookie(event, REFRESH_TOKEN_STORAGE_KEY, refreshToken,
|
|
31
|
+
setCookie(event, REFRESH_TOKEN_STORAGE_KEY, refreshToken, tokenCookieOptions(event));
|
|
32
32
|
return { ...data, token };
|
|
33
33
|
} catch (err) {
|
|
34
34
|
throw createError({
|
|
@@ -2,7 +2,7 @@ import { defineEventHandler, createError, parseCookies, getRequestHeader } from
|
|
|
2
2
|
import { $fetch } from 'ofetch';
|
|
3
3
|
import { a as AUTH_ENDPOINT } from '../../chunks/auth.constant-CnGo0q42.js';
|
|
4
4
|
import { b as HTTP_HEADER } from '../../chunks/http.constant-BzH5tJTG.js';
|
|
5
|
-
import { r as readSdkConfig } from '../../chunks/_shared-
|
|
5
|
+
import { r as readSdkConfig } from '../../chunks/_shared-DWYblQqx.js';
|
|
6
6
|
|
|
7
7
|
const cbsStart_post = defineEventHandler(async (event) => {
|
|
8
8
|
const { cmsUrl, clientId } = readSdkConfig(event);
|
|
@@ -2,7 +2,7 @@ import { defineEventHandler, createError, getQuery, parseCookies, getRequestHead
|
|
|
2
2
|
import { $fetch } from 'ofetch';
|
|
3
3
|
import { a as AUTH_ENDPOINT } from '../../chunks/auth.constant-CnGo0q42.js';
|
|
4
4
|
import { b as HTTP_HEADER } from '../../chunks/http.constant-BzH5tJTG.js';
|
|
5
|
-
import { r as readSdkConfig,
|
|
5
|
+
import { r as readSdkConfig, t as tokenCookieOptions } from '../../chunks/_shared-DWYblQqx.js';
|
|
6
6
|
import { T as TOKEN_STORAGE_KEY, R as REFRESH_TOKEN_STORAGE_KEY } from '../../chunks/storage.constant-CVWam5ls.js';
|
|
7
7
|
|
|
8
8
|
const idpCallback_get = defineEventHandler(async (event) => {
|
|
@@ -33,9 +33,9 @@ const idpCallback_get = defineEventHandler(async (event) => {
|
|
|
33
33
|
});
|
|
34
34
|
const token = data.accessToken ?? data.access_token ?? "";
|
|
35
35
|
const refreshToken = data.refreshToken ?? data.refresh_token ?? "";
|
|
36
|
-
if (token) setCookie(event, TOKEN_STORAGE_KEY, token,
|
|
36
|
+
if (token) setCookie(event, TOKEN_STORAGE_KEY, token, tokenCookieOptions(event));
|
|
37
37
|
if (refreshToken)
|
|
38
|
-
setCookie(event, REFRESH_TOKEN_STORAGE_KEY, refreshToken,
|
|
38
|
+
setCookie(event, REFRESH_TOKEN_STORAGE_KEY, refreshToken, tokenCookieOptions(event));
|
|
39
39
|
return { ...data, token };
|
|
40
40
|
} catch (err) {
|
|
41
41
|
const beData = err?.data ?? {};
|
|
@@ -2,7 +2,7 @@ import { defineEventHandler, createError, getQuery, parseCookies } from 'h3';
|
|
|
2
2
|
import { $fetch } from 'ofetch';
|
|
3
3
|
import { a as AUTH_ENDPOINT } from '../../chunks/auth.constant-CnGo0q42.js';
|
|
4
4
|
import { b as HTTP_HEADER } from '../../chunks/http.constant-BzH5tJTG.js';
|
|
5
|
-
import { r as readSdkConfig } from '../../chunks/_shared-
|
|
5
|
+
import { r as readSdkConfig } from '../../chunks/_shared-DWYblQqx.js';
|
|
6
6
|
import { T as TOKEN_STORAGE_KEY } from '../../chunks/storage.constant-CVWam5ls.js';
|
|
7
7
|
|
|
8
8
|
const idpLinkCallback_get = defineEventHandler(async (event) => {
|
|
@@ -2,7 +2,7 @@ import { defineEventHandler, createError, getQuery, parseCookies } from 'h3';
|
|
|
2
2
|
import { $fetch } from 'ofetch';
|
|
3
3
|
import { a as AUTH_ENDPOINT } from '../../chunks/auth.constant-CnGo0q42.js';
|
|
4
4
|
import { b as HTTP_HEADER } from '../../chunks/http.constant-BzH5tJTG.js';
|
|
5
|
-
import { r as readSdkConfig } from '../../chunks/_shared-
|
|
5
|
+
import { r as readSdkConfig } from '../../chunks/_shared-DWYblQqx.js';
|
|
6
6
|
import { T as TOKEN_STORAGE_KEY } from '../../chunks/storage.constant-CVWam5ls.js';
|
|
7
7
|
|
|
8
8
|
const idpLinkStart_get = defineEventHandler(async (event) => {
|
|
@@ -2,7 +2,7 @@ import { defineEventHandler, createError, readBody, parseCookies } from 'h3';
|
|
|
2
2
|
import { $fetch } from 'ofetch';
|
|
3
3
|
import { a as AUTH_ENDPOINT } from '../../chunks/auth.constant-CnGo0q42.js';
|
|
4
4
|
import { b as HTTP_HEADER } from '../../chunks/http.constant-BzH5tJTG.js';
|
|
5
|
-
import { r as readSdkConfig } from '../../chunks/_shared-
|
|
5
|
+
import { r as readSdkConfig } from '../../chunks/_shared-DWYblQqx.js';
|
|
6
6
|
import { T as TOKEN_STORAGE_KEY } from '../../chunks/storage.constant-CVWam5ls.js';
|
|
7
7
|
|
|
8
8
|
const idpLink_post = defineEventHandler(async (event) => {
|
|
@@ -2,7 +2,7 @@ import { defineEventHandler, createError, getQuery, parseCookies, getRequestHead
|
|
|
2
2
|
import { $fetch } from 'ofetch';
|
|
3
3
|
import { a as AUTH_ENDPOINT } from '../../chunks/auth.constant-CnGo0q42.js';
|
|
4
4
|
import { b as HTTP_HEADER } from '../../chunks/http.constant-BzH5tJTG.js';
|
|
5
|
-
import { r as readSdkConfig } from '../../chunks/_shared-
|
|
5
|
+
import { r as readSdkConfig } from '../../chunks/_shared-DWYblQqx.js';
|
|
6
6
|
|
|
7
7
|
const idpLogin_get = defineEventHandler(async (event) => {
|
|
8
8
|
const { cmsUrl, clientId } = readSdkConfig(event);
|
|
@@ -2,7 +2,7 @@ import { defineEventHandler, createError, parseCookies } from 'h3';
|
|
|
2
2
|
import { $fetch } from 'ofetch';
|
|
3
3
|
import { a as AUTH_ENDPOINT } from '../../chunks/auth.constant-CnGo0q42.js';
|
|
4
4
|
import { b as HTTP_HEADER } from '../../chunks/http.constant-BzH5tJTG.js';
|
|
5
|
-
import { r as readSdkConfig } from '../../chunks/_shared-
|
|
5
|
+
import { r as readSdkConfig } from '../../chunks/_shared-DWYblQqx.js';
|
|
6
6
|
import { T as TOKEN_STORAGE_KEY } from '../../chunks/storage.constant-CVWam5ls.js';
|
|
7
7
|
|
|
8
8
|
const idpMe_get = defineEventHandler(async (event) => {
|
|
@@ -2,7 +2,7 @@ import { defineEventHandler, createError, getQuery, parseCookies } from 'h3';
|
|
|
2
2
|
import { $fetch } from 'ofetch';
|
|
3
3
|
import { a as AUTH_ENDPOINT } from '../../chunks/auth.constant-CnGo0q42.js';
|
|
4
4
|
import { b as HTTP_HEADER } from '../../chunks/http.constant-BzH5tJTG.js';
|
|
5
|
-
import { r as readSdkConfig } from '../../chunks/_shared-
|
|
5
|
+
import { r as readSdkConfig } from '../../chunks/_shared-DWYblQqx.js';
|
|
6
6
|
import { T as TOKEN_STORAGE_KEY } from '../../chunks/storage.constant-CVWam5ls.js';
|
|
7
7
|
|
|
8
8
|
const idpUnlink_delete = defineEventHandler(async (event) => {
|
|
@@ -2,7 +2,7 @@ import { defineEventHandler, createError, readBody, parseCookies, getRequestHead
|
|
|
2
2
|
import { $fetch } from 'ofetch';
|
|
3
3
|
import { a as AUTH_ENDPOINT } from '../../chunks/auth.constant-CnGo0q42.js';
|
|
4
4
|
import { b as HTTP_HEADER } from '../../chunks/http.constant-BzH5tJTG.js';
|
|
5
|
-
import { r as readSdkConfig,
|
|
5
|
+
import { r as readSdkConfig, t as tokenCookieOptions } from '../../chunks/_shared-DWYblQqx.js';
|
|
6
6
|
import { T as TOKEN_STORAGE_KEY, R as REFRESH_TOKEN_STORAGE_KEY } from '../../chunks/storage.constant-CVWam5ls.js';
|
|
7
7
|
|
|
8
8
|
const login_post = defineEventHandler(async (event) => {
|
|
@@ -29,9 +29,9 @@ const login_post = defineEventHandler(async (event) => {
|
|
|
29
29
|
const data = response._data ?? {};
|
|
30
30
|
const token = data.accessToken ?? data.access_token ?? "";
|
|
31
31
|
const refreshToken = data.refreshToken ?? data.refresh_token ?? "";
|
|
32
|
-
if (token) setCookie(event, TOKEN_STORAGE_KEY, token,
|
|
32
|
+
if (token) setCookie(event, TOKEN_STORAGE_KEY, token, tokenCookieOptions(event));
|
|
33
33
|
if (refreshToken)
|
|
34
|
-
setCookie(event, REFRESH_TOKEN_STORAGE_KEY, refreshToken,
|
|
34
|
+
setCookie(event, REFRESH_TOKEN_STORAGE_KEY, refreshToken, tokenCookieOptions(event));
|
|
35
35
|
return { ...data, token };
|
|
36
36
|
} catch (err) {
|
|
37
37
|
throw createError({
|
|
@@ -2,7 +2,7 @@ import { defineEventHandler, parseCookies, deleteCookie } from 'h3';
|
|
|
2
2
|
import { $fetch } from 'ofetch';
|
|
3
3
|
import { a as AUTH_ENDPOINT } from '../../chunks/auth.constant-CnGo0q42.js';
|
|
4
4
|
import { b as HTTP_HEADER } from '../../chunks/http.constant-BzH5tJTG.js';
|
|
5
|
-
import { r as readSdkConfig, T as TOKEN_COOKIE_OPTIONS } from '../../chunks/_shared-
|
|
5
|
+
import { r as readSdkConfig, T as TOKEN_COOKIE_OPTIONS } from '../../chunks/_shared-DWYblQqx.js';
|
|
6
6
|
import { T as TOKEN_STORAGE_KEY, R as REFRESH_TOKEN_STORAGE_KEY } from '../../chunks/storage.constant-CVWam5ls.js';
|
|
7
7
|
|
|
8
8
|
const logout_post = defineEventHandler(async (event) => {
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { defineEventHandler, createError, parseCookies, setCookie } from 'h3';
|
|
2
|
+
import { useRuntimeConfig } from '#imports';
|
|
2
3
|
import { $fetch } from 'ofetch';
|
|
3
4
|
import { a as AUTH_ENDPOINT } from '../../chunks/auth.constant-CnGo0q42.js';
|
|
4
5
|
import { b as HTTP_HEADER, R as RESPONSE_CASING_VALUE } from '../../chunks/http.constant-BzH5tJTG.js';
|
|
5
|
-
import { r as readSdkConfig,
|
|
6
|
+
import { r as readSdkConfig, t as tokenCookieOptions } from '../../chunks/_shared-DWYblQqx.js';
|
|
6
7
|
import { R as REFRESH_TOKEN_STORAGE_KEY, T as TOKEN_STORAGE_KEY } from '../../chunks/storage.constant-CVWam5ls.js';
|
|
7
8
|
|
|
8
9
|
const refresh_post = defineEventHandler(async (event) => {
|
|
@@ -14,7 +15,20 @@ const refresh_post = defineEventHandler(async (event) => {
|
|
|
14
15
|
throw createError({ statusCode: 401, message: "No refresh token" });
|
|
15
16
|
}
|
|
16
17
|
const snake = requestCasing === RESPONSE_CASING_VALUE.SNAKE;
|
|
18
|
+
const config = useRuntimeConfig(event);
|
|
19
|
+
const clientSecret = config?.cmsClientSecret ?? "";
|
|
17
20
|
const body = snake ? { grant_type: "refresh_token", refresh_token: refreshToken } : { grantType: "refresh_token", refreshToken };
|
|
21
|
+
if (clientSecret) {
|
|
22
|
+
body.client_id = clientId;
|
|
23
|
+
body.client_secret = clientSecret;
|
|
24
|
+
if (!snake) {
|
|
25
|
+
body.grant_type = body.grantType;
|
|
26
|
+
body.refresh_token = body.refreshToken;
|
|
27
|
+
} else {
|
|
28
|
+
body.grantType = body.grant_type;
|
|
29
|
+
body.refreshToken = body.refresh_token;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
18
32
|
const headers = {
|
|
19
33
|
[HTTP_HEADER.CLIENT_ID]: clientId || ""
|
|
20
34
|
};
|
|
@@ -31,8 +45,9 @@ const refresh_post = defineEventHandler(async (event) => {
|
|
|
31
45
|
});
|
|
32
46
|
const token = data.accessToken ?? data.access_token ?? "";
|
|
33
47
|
const newRefresh = data.refreshToken ?? data.refresh_token ?? "";
|
|
34
|
-
if (token) setCookie(event, TOKEN_STORAGE_KEY, token,
|
|
35
|
-
if (newRefresh)
|
|
48
|
+
if (token) setCookie(event, TOKEN_STORAGE_KEY, token, tokenCookieOptions(event));
|
|
49
|
+
if (newRefresh)
|
|
50
|
+
setCookie(event, REFRESH_TOKEN_STORAGE_KEY, newRefresh, tokenCookieOptions(event));
|
|
36
51
|
return { ...data, token };
|
|
37
52
|
} catch (err) {
|
|
38
53
|
throw createError({
|
|
@@ -2,7 +2,7 @@ import { defineEventHandler, createError, parseCookies } from 'h3';
|
|
|
2
2
|
import { $fetch } from 'ofetch';
|
|
3
3
|
import { a as AUTHZ_ENDPOINT } from '../../chunks/authz.constant-BqX8Nzw6.js';
|
|
4
4
|
import { b as HTTP_HEADER } from '../../chunks/http.constant-BzH5tJTG.js';
|
|
5
|
-
import { r as readSdkConfig } from '../../chunks/_shared-
|
|
5
|
+
import { r as readSdkConfig } from '../../chunks/_shared-DWYblQqx.js';
|
|
6
6
|
import { T as TOKEN_STORAGE_KEY } from '../../chunks/storage.constant-CVWam5ls.js';
|
|
7
7
|
|
|
8
8
|
const portalAccess_get = defineEventHandler(async (event) => {
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { $fetch } from 'ofetch';
|
|
2
|
+
import { defineEventHandler, getQuery, createError, setCookie, sendRedirect } from 'h3';
|
|
3
|
+
import { useRuntimeConfig } from '#imports';
|
|
4
|
+
import { c as consumeTransaction, a as clearTransactionCookie, O as OAUTH_GRANT_AUTHORIZATION_CODE, s as safeReturnPath } from '../../chunks/_txn-DmQZNq48.js';
|
|
5
|
+
import { T as TOKEN_STORAGE_KEY, R as REFRESH_TOKEN_STORAGE_KEY } from '../../chunks/storage.constant-CVWam5ls.js';
|
|
6
|
+
import { r as readSdkConfig, t as tokenCookieOptions } from '../../chunks/_shared-DWYblQqx.js';
|
|
7
|
+
|
|
8
|
+
const callback_get = defineEventHandler(async (event) => {
|
|
9
|
+
const query = getQuery(event);
|
|
10
|
+
const code = typeof query.code === "string" ? query.code : "";
|
|
11
|
+
const state = typeof query.state === "string" ? query.state : "";
|
|
12
|
+
const oauthError = typeof query.error === "string" ? query.error : "";
|
|
13
|
+
const fail = async (reason) => {
|
|
14
|
+
clearTransactionCookie(event);
|
|
15
|
+
await sendRedirect(event, `/login?auth_error=${encodeURIComponent(reason)}`, 302);
|
|
16
|
+
};
|
|
17
|
+
if (oauthError) return await fail(oauthError);
|
|
18
|
+
if (!code || !state) return await fail("missing_code_or_state");
|
|
19
|
+
const txn = consumeTransaction(event, state);
|
|
20
|
+
if (!txn) return await fail("invalid_state");
|
|
21
|
+
clearTransactionCookie(event);
|
|
22
|
+
const { cmsUrl, clientId } = readSdkConfig(event);
|
|
23
|
+
if (!cmsUrl) throw createError({ statusCode: 500, message: "CMS URL not configured" });
|
|
24
|
+
const secret = useRuntimeConfig(event).cmsClientSecret;
|
|
25
|
+
if (!secret) throw createError({ statusCode: 500, message: "cmsClientSecret not configured" });
|
|
26
|
+
let tokenResponse;
|
|
27
|
+
try {
|
|
28
|
+
tokenResponse = await $fetch("/api/oauth/token", {
|
|
29
|
+
baseURL: cmsUrl,
|
|
30
|
+
method: "POST",
|
|
31
|
+
body: {
|
|
32
|
+
grant_type: OAUTH_GRANT_AUTHORIZATION_CODE,
|
|
33
|
+
code,
|
|
34
|
+
client_id: clientId,
|
|
35
|
+
client_secret: secret,
|
|
36
|
+
redirect_uri: txn.redirectUri,
|
|
37
|
+
code_verifier: txn.codeVerifier
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
} catch {
|
|
41
|
+
return await fail("token_exchange_failed");
|
|
42
|
+
}
|
|
43
|
+
const accessToken = tokenResponse.accessToken ?? tokenResponse.access_token ?? "";
|
|
44
|
+
const refreshToken = tokenResponse.refreshToken ?? tokenResponse.refresh_token ?? "";
|
|
45
|
+
if (!accessToken) return await fail("token_exchange_failed");
|
|
46
|
+
setCookie(event, TOKEN_STORAGE_KEY, accessToken, tokenCookieOptions(event));
|
|
47
|
+
if (refreshToken) {
|
|
48
|
+
setCookie(event, REFRESH_TOKEN_STORAGE_KEY, refreshToken, tokenCookieOptions(event));
|
|
49
|
+
}
|
|
50
|
+
await sendRedirect(event, safeReturnPath(txn.returnTo), 302);
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
export { callback_get as default };
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { defineEventHandler, createError, getQuery, getRequestURL, sendRedirect } from 'h3';
|
|
2
|
+
import { useRuntimeConfig } from '#imports';
|
|
3
|
+
import { s as safeReturnPath, b as createPkce, d as saveTransaction, e as setTransactionCookie, f as OAUTH_PROXY_PATH, g as codeChallenge, P as PKCE_METHOD } from '../../chunks/_txn-DmQZNq48.js';
|
|
4
|
+
import { r as readSdkConfig } from '../../chunks/_shared-DWYblQqx.js';
|
|
5
|
+
|
|
6
|
+
const start_get = defineEventHandler(async (event) => {
|
|
7
|
+
const config = useRuntimeConfig(event);
|
|
8
|
+
const centralAuthUrl = config?.public?.centralAuthUrl ?? "";
|
|
9
|
+
if (!centralAuthUrl) {
|
|
10
|
+
throw createError({ statusCode: 500, message: "centralAuthUrl not configured" });
|
|
11
|
+
}
|
|
12
|
+
const { clientId } = readSdkConfig(event);
|
|
13
|
+
if (!clientId) {
|
|
14
|
+
throw createError({ statusCode: 500, message: "clientId not configured" });
|
|
15
|
+
}
|
|
16
|
+
const query = getQuery(event);
|
|
17
|
+
const returnTo = safeReturnPath(typeof query.redirect === "string" ? query.redirect : void 0);
|
|
18
|
+
const origin = new URL(getRequestURL(event)).origin;
|
|
19
|
+
const redirectUri = `${origin}${OAUTH_PROXY_PATH.CALLBACK}`;
|
|
20
|
+
const pkce = createPkce();
|
|
21
|
+
const txnId = saveTransaction({
|
|
22
|
+
state: pkce.state,
|
|
23
|
+
codeVerifier: pkce.verifier,
|
|
24
|
+
redirectUri,
|
|
25
|
+
returnTo,
|
|
26
|
+
createdAt: Date.now()
|
|
27
|
+
});
|
|
28
|
+
setTransactionCookie(event, txnId);
|
|
29
|
+
const authorize = new URL(centralAuthUrl);
|
|
30
|
+
authorize.searchParams.set("response_type", "code");
|
|
31
|
+
authorize.searchParams.set("client_id", clientId);
|
|
32
|
+
authorize.searchParams.set("redirect_uri", redirectUri);
|
|
33
|
+
authorize.searchParams.set("scope", readOAuthScope(event));
|
|
34
|
+
authorize.searchParams.set("state", pkce.state);
|
|
35
|
+
authorize.searchParams.set("code_challenge", codeChallenge(pkce.verifier));
|
|
36
|
+
authorize.searchParams.set("code_challenge_method", PKCE_METHOD);
|
|
37
|
+
authorize.searchParams.set("prompt", "login");
|
|
38
|
+
return await sendRedirect(event, authorize.toString(), 302);
|
|
39
|
+
});
|
|
40
|
+
function readOAuthScope(event) {
|
|
41
|
+
const config = useRuntimeConfig(event);
|
|
42
|
+
const opts = config?.public?.cmsSdkOptions ?? {};
|
|
43
|
+
return opts.oauthScope || "read";
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export { start_get as default };
|