@base44-preview/sdk 0.8.48-pr.282.2b05017 → 0.8.48-pr.282.8affbe6
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/client.js
CHANGED
|
@@ -67,7 +67,11 @@ export function createClient(config) {
|
|
|
67
67
|
if (embedOtt) {
|
|
68
68
|
markEmbeddedTab();
|
|
69
69
|
}
|
|
70
|
-
|
|
70
|
+
// What an app passes as `token` is whatever getAccessToken() returned as the
|
|
71
|
+
// page loaded. In an embedded frame that is the one-time token itself, or a
|
|
72
|
+
// token an earlier visitor left in storage; neither is this session.
|
|
73
|
+
const configToken = embedded ? undefined : token;
|
|
74
|
+
let currentToken = configToken !== null && configToken !== void 0 ? configToken : null;
|
|
71
75
|
const socketConfig = {
|
|
72
76
|
serverUrl,
|
|
73
77
|
mountPath: "/ws-user-apps/socket.io/",
|
|
@@ -75,7 +79,7 @@ export function createClient(config) {
|
|
|
75
79
|
appId,
|
|
76
80
|
// null (not undefined): an embedded frame's only identity is the one the
|
|
77
81
|
// platform minted, so the socket must not fall back to a stored token.
|
|
78
|
-
token: embedded ? null :
|
|
82
|
+
token: embedded ? null : configToken,
|
|
79
83
|
};
|
|
80
84
|
let socket = null;
|
|
81
85
|
const getSocket = () => {
|
|
@@ -99,19 +103,19 @@ export function createClient(config) {
|
|
|
99
103
|
const axiosClient = createAxiosClient({
|
|
100
104
|
baseURL: `${serverUrl}/api`,
|
|
101
105
|
headers,
|
|
102
|
-
token,
|
|
106
|
+
token: configToken,
|
|
103
107
|
onError: options === null || options === void 0 ? void 0 : options.onError,
|
|
104
108
|
});
|
|
105
109
|
const functionsAxiosClient = createAxiosClient({
|
|
106
110
|
baseURL: `${serverUrl}/api`,
|
|
107
111
|
headers: functionHeaders,
|
|
108
|
-
token,
|
|
112
|
+
token: configToken,
|
|
109
113
|
interceptResponses: false,
|
|
110
114
|
onError: options === null || options === void 0 ? void 0 : options.onError,
|
|
111
115
|
});
|
|
112
116
|
const serviceRoleHeaders = {
|
|
113
117
|
...headers,
|
|
114
|
-
...(
|
|
118
|
+
...(configToken ? { "on-behalf-of": `Bearer ${configToken}` } : {}),
|
|
115
119
|
};
|
|
116
120
|
const serviceRoleAxiosClient = createAxiosClient({
|
|
117
121
|
baseURL: `${serverUrl}/api`,
|
|
@@ -137,7 +141,7 @@ export function createClient(config) {
|
|
|
137
141
|
const userAuthModule = createAuthModule(axiosClient, functionsAxiosClient, appId, {
|
|
138
142
|
appBaseUrl: normalizedAppBaseUrl,
|
|
139
143
|
serverUrl,
|
|
140
|
-
token,
|
|
144
|
+
token: configToken,
|
|
141
145
|
embedded,
|
|
142
146
|
});
|
|
143
147
|
// Apply the access token before any module that may issue authenticated
|
|
@@ -147,7 +151,7 @@ export function createClient(config) {
|
|
|
147
151
|
// An embedded load skips this: its session comes from the exchange below,
|
|
148
152
|
// and a token an earlier visitor left in storage must not become it.
|
|
149
153
|
if (inBrowser && !embedded) {
|
|
150
|
-
const accessToken =
|
|
154
|
+
const accessToken = configToken || getAccessToken();
|
|
151
155
|
if (accessToken) {
|
|
152
156
|
currentToken = accessToken;
|
|
153
157
|
userAuthModule.setToken(accessToken);
|
|
@@ -5,6 +5,8 @@ import { GetAccessTokenOptions, SaveAccessTokenOptions, RemoveAccessTokenOptions
|
|
|
5
5
|
* Low-level utility for manually retrieving tokens. In most cases, the Base44 client handles
|
|
6
6
|
* token management automatically. This function is useful for custom authentication flows or when you need direct access to stored tokens. Requires a browser environment and can't be used in the backend.
|
|
7
7
|
*
|
|
8
|
+
* When a host platform has embedded the app with a one-time token (`?ott=`), that token is returned as it stands: it is what {@linkcode createClient} trades for the session, so a page that gates on "is there a token?" as it loads sees one. It is neither stored nor removed from the URL here.
|
|
9
|
+
*
|
|
8
10
|
* @internal
|
|
9
11
|
*
|
|
10
12
|
* @param options - Configuration options for token retrieval.
|
package/dist/utils/auth-utils.js
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
|
+
import { EMBED_TOKEN_PARAM } from "./embed-session.js";
|
|
1
2
|
/**
|
|
2
3
|
* Retrieves an access token from URL parameters or local storage.
|
|
3
4
|
*
|
|
4
5
|
* Low-level utility for manually retrieving tokens. In most cases, the Base44 client handles
|
|
5
6
|
* token management automatically. This function is useful for custom authentication flows or when you need direct access to stored tokens. Requires a browser environment and can't be used in the backend.
|
|
6
7
|
*
|
|
8
|
+
* When a host platform has embedded the app with a one-time token (`?ott=`), that token is returned as it stands: it is what {@linkcode createClient} trades for the session, so a page that gates on "is there a token?" as it loads sees one. It is neither stored nor removed from the URL here.
|
|
9
|
+
*
|
|
7
10
|
* @internal
|
|
8
11
|
*
|
|
9
12
|
* @param options - Configuration options for token retrieval.
|
|
@@ -56,6 +59,14 @@ export function getAccessToken(options = {}) {
|
|
|
56
59
|
}
|
|
57
60
|
return token;
|
|
58
61
|
}
|
|
62
|
+
// A platform-embedded load carries a one-time token instead. It is not a
|
|
63
|
+
// session yet — createClient takes it off the URL and exchanges it — but
|
|
64
|
+
// it is the identity this load arrives with, and callers that read this
|
|
65
|
+
// once as the page loads must not conclude there is none.
|
|
66
|
+
const embedToken = urlParams.get(EMBED_TOKEN_PARAM);
|
|
67
|
+
if (embedToken) {
|
|
68
|
+
return embedToken;
|
|
69
|
+
}
|
|
59
70
|
}
|
|
60
71
|
catch (e) {
|
|
61
72
|
console.error("Error retrieving token from URL:", e);
|
|
@@ -9,6 +9,8 @@
|
|
|
9
9
|
*
|
|
10
10
|
* @internal
|
|
11
11
|
*/
|
|
12
|
+
/** The query parameter a host platform puts the one-time token on. @internal */
|
|
13
|
+
export declare const EMBED_TOKEN_PARAM = "ott";
|
|
12
14
|
/**
|
|
13
15
|
* Reads the one-time token off the current URL and strips it, so it is never
|
|
14
16
|
* left in the address bar, in history, or in a shared link.
|
|
@@ -9,7 +9,8 @@
|
|
|
9
9
|
*
|
|
10
10
|
* @internal
|
|
11
11
|
*/
|
|
12
|
-
|
|
12
|
+
/** The query parameter a host platform puts the one-time token on. @internal */
|
|
13
|
+
export const EMBED_TOKEN_PARAM = "ott";
|
|
13
14
|
const EMBED_TAB_KEY = "base44_embed_session";
|
|
14
15
|
const GRANT_TYPE = "urn:ietf:params:oauth:grant-type:token-exchange";
|
|
15
16
|
const SUBJECT_TOKEN_TYPE = "urn:base44:params:oauth:token-type:embed-ott";
|
|
@@ -28,11 +29,11 @@ export function takeEmbedTokenFromUrl() {
|
|
|
28
29
|
}
|
|
29
30
|
try {
|
|
30
31
|
const url = new URL(window.location.href);
|
|
31
|
-
const ott = url.searchParams.get(
|
|
32
|
+
const ott = url.searchParams.get(EMBED_TOKEN_PARAM);
|
|
32
33
|
if (!ott) {
|
|
33
34
|
return null;
|
|
34
35
|
}
|
|
35
|
-
url.searchParams.delete(
|
|
36
|
+
url.searchParams.delete(EMBED_TOKEN_PARAM);
|
|
36
37
|
window.history.replaceState(window.history.state, "", url.toString());
|
|
37
38
|
return ott;
|
|
38
39
|
}
|