@base44-preview/sdk 0.8.19-pr.134.bf04bef → 0.8.19-pr.135.721e301
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/modules/auth.js
CHANGED
|
@@ -1,50 +1,3 @@
|
|
|
1
|
-
const POPUP_AUTH_DOMAIN_REGEX = /^(preview-sandbox--|preview--|checkpoint--)[^.]+\./;
|
|
2
|
-
function isPopupAuthDomain() {
|
|
3
|
-
if (typeof window === "undefined")
|
|
4
|
-
return false;
|
|
5
|
-
return POPUP_AUTH_DOMAIN_REGEX.test(window.location.hostname);
|
|
6
|
-
}
|
|
7
|
-
/**
|
|
8
|
-
* Opens a URL in a centered popup and, once the OAuth provider redirects
|
|
9
|
-
* back to our origin, mirrors that callback URL in the current window so the
|
|
10
|
-
* iframe processes the access_token query param exactly as a normal redirect
|
|
11
|
-
* would.
|
|
12
|
-
*
|
|
13
|
-
* @param url - The URL to open in the popup.
|
|
14
|
-
*/
|
|
15
|
-
function loginViaPopup(url) {
|
|
16
|
-
const width = 500;
|
|
17
|
-
const height = 600;
|
|
18
|
-
const left = Math.round(window.screenX + (window.outerWidth - width) / 2);
|
|
19
|
-
const top = Math.round(window.screenY + (window.outerHeight - height) / 2);
|
|
20
|
-
const popup = window.open(url, "base44_auth", `width=${width},height=${height},left=${left},top=${top},resizable=yes,scrollbars=yes`);
|
|
21
|
-
if (!popup) {
|
|
22
|
-
return;
|
|
23
|
-
}
|
|
24
|
-
const pollTimer = setInterval(() => {
|
|
25
|
-
if (popup.closed) {
|
|
26
|
-
clearInterval(pollTimer);
|
|
27
|
-
return;
|
|
28
|
-
}
|
|
29
|
-
try {
|
|
30
|
-
// Accessing popup.location.href throws a cross-origin error while the
|
|
31
|
-
// OAuth provider's pages are open — that's expected and means the flow
|
|
32
|
-
// is still in progress. Once it stops throwing, the popup has landed
|
|
33
|
-
// back on our origin with the callback URL (e.g. ?access_token=...).
|
|
34
|
-
const callbackUrl = popup.location.href;
|
|
35
|
-
if (new URL(callbackUrl).origin === window.location.origin) {
|
|
36
|
-
clearInterval(pollTimer);
|
|
37
|
-
popup.close();
|
|
38
|
-
// Redirect the iframe to the same URL the popup landed on so it
|
|
39
|
-
// processes the token from the query params as it normally would.
|
|
40
|
-
window.location.href = callbackUrl;
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
catch (_a) {
|
|
44
|
-
// Still on the OAuth provider's domain — keep polling
|
|
45
|
-
}
|
|
46
|
-
}, 300);
|
|
47
|
-
}
|
|
48
1
|
/**
|
|
49
2
|
* Creates the auth module for the Base44 SDK.
|
|
50
3
|
*
|
|
@@ -84,24 +37,10 @@ export function createAuthModule(axios, functionsAxiosClient, appId, options) {
|
|
|
84
37
|
loginWithProvider(provider, fromUrl = "/") {
|
|
85
38
|
// Build the full redirect URL
|
|
86
39
|
const redirectUrl = new URL(fromUrl, window.location.origin).toString();
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
authPath = `/apps/${appId}/auth/sso/login`;
|
|
92
|
-
}
|
|
93
|
-
else {
|
|
94
|
-
// Google is the default provider, so no provider path segment needed
|
|
95
|
-
const providerPath = provider === "google" ? "" : `/${provider}`;
|
|
96
|
-
authPath = `/apps/auth${providerPath}/login`;
|
|
97
|
-
}
|
|
98
|
-
const loginUrl = `${options.appBaseUrl}/api${authPath}?${queryParams}`;
|
|
99
|
-
// On preview/sandbox/checkpoint domains the app runs inside an iframe —
|
|
100
|
-
// use a popup to avoid OAuth providers blocking iframe navigation.
|
|
101
|
-
if (isPopupAuthDomain()) {
|
|
102
|
-
return loginViaPopup(loginUrl);
|
|
103
|
-
}
|
|
104
|
-
// Default: full-page redirect
|
|
40
|
+
// Build the provider login URL (google is the default, so no provider path needed)
|
|
41
|
+
const providerPath = provider === "google" ? "" : `/${provider}`;
|
|
42
|
+
const loginUrl = `${options.appBaseUrl}/api/apps/auth${providerPath}/login?app_id=${appId}&from_url=${encodeURIComponent(redirectUrl)}`;
|
|
43
|
+
// Redirect to the provider login page
|
|
105
44
|
window.location.href = loginUrl;
|
|
106
45
|
},
|
|
107
46
|
// Logout the current user
|
|
@@ -185,9 +185,8 @@ export interface AuthModule {
|
|
|
185
185
|
* - `'microsoft'` - {@link https://learn.microsoft.com/en-us/entra/identity-platform/v2-oauth2-auth-code-flow | Microsoft OAuth}. Enable Microsoft in your app's authentication settings before specifying this provider.
|
|
186
186
|
* - `'facebook'` - {@link https://developers.facebook.com/docs/facebook-login | Facebook Login}. Enable Facebook in your app's authentication settings before using.
|
|
187
187
|
* - `'apple'` - {@link https://developer.apple.com/sign-in-with-apple/ | Sign in with Apple}. Enable Apple in your app's authentication settings before using this provider.
|
|
188
|
-
* - `'sso'` - Enterprise SSO. Enable SSO in your app's authentication settings before using this provider.
|
|
189
188
|
*
|
|
190
|
-
* @param provider - The authentication provider to use: `'google'`, `'microsoft'`, `'facebook'`,
|
|
189
|
+
* @param provider - The authentication provider to use: `'google'`, `'microsoft'`, `'facebook'`, or `'apple'`.
|
|
191
190
|
* @param fromUrl - URL to redirect to after successful authentication. Defaults to `'/'`.
|
|
192
191
|
*
|
|
193
192
|
* @example
|
|
@@ -207,12 +206,6 @@ export interface AuthModule {
|
|
|
207
206
|
* // Apple
|
|
208
207
|
* base44.auth.loginWithProvider('apple', '/dashboard');
|
|
209
208
|
* ```
|
|
210
|
-
*
|
|
211
|
-
* @example
|
|
212
|
-
* ```typescript
|
|
213
|
-
* // SSO
|
|
214
|
-
* base44.auth.loginWithProvider('sso', '/dashboard');
|
|
215
|
-
* ```
|
|
216
209
|
*/
|
|
217
210
|
loginWithProvider(provider: string, fromUrl?: string): void;
|
|
218
211
|
/**
|
|
@@ -18,5 +18,17 @@ export function createConnectorsModule(axios, appId) {
|
|
|
18
18
|
// @ts-expect-error
|
|
19
19
|
return response.access_token;
|
|
20
20
|
},
|
|
21
|
+
async getConnection(integrationType) {
|
|
22
|
+
var _a;
|
|
23
|
+
if (!integrationType || typeof integrationType !== "string") {
|
|
24
|
+
throw new Error("Integration type is required and must be a string");
|
|
25
|
+
}
|
|
26
|
+
const response = await axios.get(`/apps/${appId}/external-auth/tokens/${integrationType}`);
|
|
27
|
+
const data = response;
|
|
28
|
+
return {
|
|
29
|
+
accessToken: data.access_token,
|
|
30
|
+
connectionConfig: (_a = data.connection_config) !== null && _a !== void 0 ? _a : null,
|
|
31
|
+
};
|
|
32
|
+
},
|
|
21
33
|
};
|
|
22
34
|
}
|
|
@@ -19,6 +19,17 @@ export type ConnectorIntegrationType = keyof ConnectorIntegrationTypeRegistry ex
|
|
|
19
19
|
*/
|
|
20
20
|
export interface ConnectorAccessTokenResponse {
|
|
21
21
|
access_token: string;
|
|
22
|
+
integration_type: string;
|
|
23
|
+
connection_config: Record<string, string> | null;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Camel-cased connection details returned by {@linkcode ConnectorsModule.getConnection | getConnection()}.
|
|
27
|
+
*/
|
|
28
|
+
export interface ConnectorConnectionResponse {
|
|
29
|
+
/** The OAuth access token for the external service. */
|
|
30
|
+
accessToken: string;
|
|
31
|
+
/** Key-value configuration for the connection, or `null` if the connector does not provide one. */
|
|
32
|
+
connectionConfig: Record<string, string> | null;
|
|
22
33
|
}
|
|
23
34
|
/**
|
|
24
35
|
* Connectors module for managing OAuth tokens for external services.
|
|
@@ -83,4 +94,35 @@ export interface ConnectorsModule {
|
|
|
83
94
|
* ```
|
|
84
95
|
*/
|
|
85
96
|
getAccessToken(integrationType: ConnectorIntegrationType): Promise<string>;
|
|
97
|
+
/**
|
|
98
|
+
* Retrieves the OAuth access token and connection configuration for a specific external integration type.
|
|
99
|
+
*
|
|
100
|
+
* Returns both the OAuth token and any additional connection configuration
|
|
101
|
+
* that the connector provides. This is useful when the external service requires
|
|
102
|
+
* extra parameters beyond the access token (e.g., a shop domain, account ID, or API base URL).
|
|
103
|
+
*
|
|
104
|
+
* @param integrationType - The type of integration, such as `'googlecalendar'`, `'slack'`, or `'github'`.
|
|
105
|
+
* @returns Promise resolving to a {@link ConnectorConnectionResponse} with `accessToken` and `connectionConfig`.
|
|
106
|
+
*
|
|
107
|
+
* @example
|
|
108
|
+
* ```typescript
|
|
109
|
+
* // Basic usage
|
|
110
|
+
* const connection = await base44.asServiceRole.connectors.getConnection('googlecalendar');
|
|
111
|
+
* console.log(connection.accessToken);
|
|
112
|
+
* console.log(connection.connectionConfig);
|
|
113
|
+
* ```
|
|
114
|
+
*
|
|
115
|
+
* @example
|
|
116
|
+
* ```typescript
|
|
117
|
+
* // Using connection config for a service that requires extra parameters
|
|
118
|
+
* const connection = await base44.asServiceRole.connectors.getConnection('shopify');
|
|
119
|
+
* const { accessToken, connectionConfig } = connection;
|
|
120
|
+
*
|
|
121
|
+
* const response = await fetch(
|
|
122
|
+
* `https://${connectionConfig?.shop}/admin/api/2024-01/products.json`,
|
|
123
|
+
* { headers: { 'X-Shopify-Access-Token': accessToken } }
|
|
124
|
+
* );
|
|
125
|
+
* ```
|
|
126
|
+
*/
|
|
127
|
+
getConnection(integrationType: ConnectorIntegrationType): Promise<ConnectorConnectionResponse>;
|
|
86
128
|
}
|