@stackframe/stack 2.4.21 → 2.4.23
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/CHANGELOG.md +18 -0
- package/dist/components/message-cards/known-error-message-card.d.mts +9 -0
- package/dist/components/message-cards/known-error-message-card.d.ts +9 -0
- package/dist/components/message-cards/known-error-message-card.js +67 -0
- package/dist/components/message-cards/known-error-message-card.js.map +1 -0
- package/dist/components/{message-card.d.mts → message-cards/message-card.d.mts} +5 -1
- package/dist/components/{message-card.d.ts → message-cards/message-card.d.ts} +5 -1
- package/dist/components/{message-card.js → message-cards/message-card.js} +10 -6
- package/dist/components/message-cards/message-card.js.map +1 -0
- package/dist/components/{redirect-message-card.d.mts → message-cards/predefined-message-card.d.mts} +3 -3
- package/dist/components/{redirect-message-card.d.ts → message-cards/predefined-message-card.d.ts} +3 -3
- package/dist/components/{redirect-message-card.js → message-cards/predefined-message-card.js} +32 -29
- package/dist/components/message-cards/predefined-message-card.js.map +1 -0
- package/dist/components/password-reset-inner.js +3 -3
- package/dist/components/password-reset-inner.js.map +1 -1
- package/dist/components-core/index.d.mts +4 -4
- package/dist/components-core/index.d.ts +4 -4
- package/dist/components-page/account-settings.js +2 -2
- package/dist/components-page/account-settings.js.map +1 -1
- package/dist/components-page/auth-page.js +2 -2
- package/dist/components-page/auth-page.js.map +1 -1
- package/dist/components-page/email-verification.js +3 -3
- package/dist/components-page/email-verification.js.map +1 -1
- package/dist/components-page/error-page.d.mts +8 -0
- package/dist/components-page/error-page.d.ts +8 -0
- package/dist/components-page/error-page.js +85 -0
- package/dist/components-page/error-page.js.map +1 -0
- package/dist/components-page/forgot-password.js +3 -3
- package/dist/components-page/forgot-password.js.map +1 -1
- package/dist/components-page/magic-link-callback.js +3 -3
- package/dist/components-page/magic-link-callback.js.map +1 -1
- package/dist/components-page/oauth-callback.js +4 -3
- package/dist/components-page/oauth-callback.js.map +1 -1
- package/dist/components-page/password-reset.js +1 -1
- package/dist/components-page/password-reset.js.map +1 -1
- package/dist/components-page/sign-out.js +2 -2
- package/dist/components-page/sign-out.js.map +1 -1
- package/dist/components-page/stack-handler.js +5 -1
- package/dist/components-page/stack-handler.js.map +1 -1
- package/dist/esm/components/message-cards/known-error-message-card.js +37 -0
- package/dist/esm/components/message-cards/known-error-message-card.js.map +1 -0
- package/dist/esm/components/message-cards/message-card.js +21 -0
- package/dist/esm/components/message-cards/message-card.js.map +1 -0
- package/dist/esm/components/{redirect-message-card.js → message-cards/predefined-message-card.js} +30 -27
- package/dist/esm/components/message-cards/predefined-message-card.js.map +1 -0
- package/dist/esm/components/password-reset-inner.js +3 -3
- package/dist/esm/components/password-reset-inner.js.map +1 -1
- package/dist/esm/components-page/account-settings.js +2 -2
- package/dist/esm/components-page/account-settings.js.map +1 -1
- package/dist/esm/components-page/auth-page.js +2 -2
- package/dist/esm/components-page/auth-page.js.map +1 -1
- package/dist/esm/components-page/email-verification.js +3 -3
- package/dist/esm/components-page/email-verification.js.map +1 -1
- package/dist/esm/components-page/error-page.js +55 -0
- package/dist/esm/components-page/error-page.js.map +1 -0
- package/dist/esm/components-page/forgot-password.js +3 -3
- package/dist/esm/components-page/forgot-password.js.map +1 -1
- package/dist/esm/components-page/magic-link-callback.js +3 -3
- package/dist/esm/components-page/magic-link-callback.js.map +1 -1
- package/dist/esm/components-page/oauth-callback.js +4 -3
- package/dist/esm/components-page/oauth-callback.js.map +1 -1
- package/dist/esm/components-page/password-reset.js +1 -1
- package/dist/esm/components-page/password-reset.js.map +1 -1
- package/dist/esm/components-page/sign-out.js +1 -1
- package/dist/esm/components-page/sign-out.js.map +1 -1
- package/dist/esm/components-page/stack-handler.js +5 -1
- package/dist/esm/components-page/stack-handler.js.map +1 -1
- package/dist/esm/index.js +1 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/lib/auth.js +30 -14
- package/dist/esm/lib/auth.js.map +1 -1
- package/dist/esm/lib/stack-app.js +141 -67
- package/dist/esm/lib/stack-app.js.map +1 -1
- package/dist/index.d.mts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/lib/auth.d.mts +13 -3
- package/dist/lib/auth.d.ts +13 -3
- package/dist/lib/auth.js +31 -14
- package/dist/lib/auth.js.map +1 -1
- package/dist/lib/stack-app.d.mts +111 -65
- package/dist/lib/stack-app.d.ts +111 -65
- package/dist/lib/stack-app.js +138 -64
- package/dist/lib/stack-app.js.map +1 -1
- package/dist/providers/component-provider.d.mts +6 -6
- package/dist/providers/component-provider.d.ts +6 -6
- package/package.json +3 -3
- package/dist/components/message-card.js.map +0 -1
- package/dist/components/redirect-message-card.js.map +0 -1
- package/dist/esm/components/message-card.js +0 -17
- package/dist/esm/components/message-card.js.map +0 -1
- package/dist/esm/components/redirect-message-card.js.map +0 -1
package/dist/index.d.mts
CHANGED
|
@@ -7,7 +7,7 @@ export { default as SignUp } from './components-page/sign-up.mjs';
|
|
|
7
7
|
export { default as EmailVerification } from './components-page/email-verification.mjs';
|
|
8
8
|
export { default as PasswordReset } from './components-page/password-reset.mjs';
|
|
9
9
|
export { default as ForgotPassword } from './components-page/forgot-password.mjs';
|
|
10
|
-
export { default as MessageCard } from './components/message-card.mjs';
|
|
10
|
+
export { default as MessageCard } from './components/message-cards/message-card.mjs';
|
|
11
11
|
export { default as CredentialSignIn } from './components/credential-sign-in.mjs';
|
|
12
12
|
export { default as CredentialSignUp } from './components/credential-sign-up.mjs';
|
|
13
13
|
export { default as OAuthButton } from './components/oauth-button.mjs';
|
package/dist/index.d.ts
CHANGED
|
@@ -7,7 +7,7 @@ export { default as SignUp } from './components-page/sign-up.js';
|
|
|
7
7
|
export { default as EmailVerification } from './components-page/email-verification.js';
|
|
8
8
|
export { default as PasswordReset } from './components-page/password-reset.js';
|
|
9
9
|
export { default as ForgotPassword } from './components-page/forgot-password.js';
|
|
10
|
-
export { default as MessageCard } from './components/message-card.js';
|
|
10
|
+
export { default as MessageCard } from './components/message-cards/message-card.js';
|
|
11
11
|
export { default as CredentialSignIn } from './components/credential-sign-in.js';
|
|
12
12
|
export { default as CredentialSignUp } from './components/credential-sign-up.js';
|
|
13
13
|
export { default as OAuthButton } from './components/oauth-button.js';
|
package/dist/index.js
CHANGED
|
@@ -66,7 +66,7 @@ var import_sign_up = __toESM(require("./components-page/sign-up"));
|
|
|
66
66
|
var import_email_verification = __toESM(require("./components-page/email-verification"));
|
|
67
67
|
var import_password_reset = __toESM(require("./components-page/password-reset"));
|
|
68
68
|
var import_forgot_password = __toESM(require("./components-page/forgot-password"));
|
|
69
|
-
var import_message_card = __toESM(require("./components/message-card"));
|
|
69
|
+
var import_message_card = __toESM(require("./components/message-cards/message-card"));
|
|
70
70
|
var import_credential_sign_in = __toESM(require("./components/credential-sign-in"));
|
|
71
71
|
var import_credential_sign_up = __toESM(require("./components/credential-sign-up"));
|
|
72
72
|
var import_oauth_button = __toESM(require("./components/oauth-button"));
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.tsx"],"sourcesContent":["export { default as StackProvider } from \"./providers/stack-provider\";\n\nexport { useUser, useStackApp } from \"./lib/hooks\";\nexport { StackClientApp, StackServerApp, StackAdminApp } from \"./lib/stack-app\";\n\nexport { default as StackHandler } from \"./components-page/stack-handler\";\nexport { default as SignIn } from \"./components-page/sign-in\";\nexport { default as SignUp } from \"./components-page/sign-up\";\nexport { default as EmailVerification } from \"./components-page/email-verification\";\nexport { default as PasswordReset } from \"./components-page/password-reset\";\nexport { default as ForgotPassword } from \"./components-page/forgot-password\";\nexport { default as MessageCard } from \"./components/message-card\";\n\nexport { default as CredentialSignIn } from \"./components/credential-sign-in\";\nexport { default as CredentialSignUp } from \"./components/credential-sign-up\";\nexport { default as OAuthButton } from \"./components/oauth-button\";\nexport { default as OAuthGroup } from \"./components/oauth-group\";\nexport { default as PasswordField } from \"./components/password-field\";\nexport { default as UserButton } from \"./components/user-button\";\nexport { default as AccountSettings } from \"./components-page/account-settings\";\nexport { default as AuthPage } from \"./components-page/auth-page\";\n\nexport { useDesign } from './providers/design-provider';\nexport type { ColorPalette } from './providers/design-provider';\nexport { useComponents } from './providers/component-provider';\nexport { StackTheme } from './providers/theme-provider';\nexport type { ThemeConfig } from './providers/theme-provider';\n\nexport type { \n CurrentUser, \n Project, \n ServerUser as ServerUser, \n ApiKeySetFirstView, \n ApiKeySet, \n ServerTeam, \n Team, \n TeamMember,\n ServerTeamMember,\n ServerPermission as Permission,\n ServerPermission,\n} from './lib/stack-app';\n\nexport * from './components-core';\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,4BAAyC;AAEzC,mBAAqC;AACrC,uBAA8D;AAE9D,2BAAwC;AACxC,qBAAkC;AAClC,qBAAkC;AAClC,gCAA6C;AAC7C,4BAAyC;AACzC,6BAA0C;AAC1C,0BAAuC;AAEvC,gCAA4C;AAC5C,gCAA4C;AAC5C,0BAAuC;AACvC,yBAAsC;AACtC,4BAAyC;AACzC,yBAAsC;AACtC,8BAA2C;AAC3C,uBAAoC;AAEpC,6BAA0B;AAE1B,gCAA8B;AAC9B,4BAA2B;AAiB3B,wBAAc,8BA1Cd;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../src/index.tsx"],"sourcesContent":["export { default as StackProvider } from \"./providers/stack-provider\";\n\nexport { useUser, useStackApp } from \"./lib/hooks\";\nexport { StackClientApp, StackServerApp, StackAdminApp } from \"./lib/stack-app\";\n\nexport { default as StackHandler } from \"./components-page/stack-handler\";\nexport { default as SignIn } from \"./components-page/sign-in\";\nexport { default as SignUp } from \"./components-page/sign-up\";\nexport { default as EmailVerification } from \"./components-page/email-verification\";\nexport { default as PasswordReset } from \"./components-page/password-reset\";\nexport { default as ForgotPassword } from \"./components-page/forgot-password\";\nexport { default as MessageCard } from \"./components/message-cards/message-card\";\n\nexport { default as CredentialSignIn } from \"./components/credential-sign-in\";\nexport { default as CredentialSignUp } from \"./components/credential-sign-up\";\nexport { default as OAuthButton } from \"./components/oauth-button\";\nexport { default as OAuthGroup } from \"./components/oauth-group\";\nexport { default as PasswordField } from \"./components/password-field\";\nexport { default as UserButton } from \"./components/user-button\";\nexport { default as AccountSettings } from \"./components-page/account-settings\";\nexport { default as AuthPage } from \"./components-page/auth-page\";\n\nexport { useDesign } from './providers/design-provider';\nexport type { ColorPalette } from './providers/design-provider';\nexport { useComponents } from './providers/component-provider';\nexport { StackTheme } from './providers/theme-provider';\nexport type { ThemeConfig } from './providers/theme-provider';\n\nexport type { \n CurrentUser, \n Project, \n ServerUser as ServerUser, \n ApiKeySetFirstView, \n ApiKeySet, \n ServerTeam, \n Team, \n TeamMember,\n ServerTeamMember,\n ServerPermission as Permission,\n ServerPermission,\n} from './lib/stack-app';\n\nexport * from './components-core';\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,4BAAyC;AAEzC,mBAAqC;AACrC,uBAA8D;AAE9D,2BAAwC;AACxC,qBAAkC;AAClC,qBAAkC;AAClC,gCAA6C;AAC7C,4BAAyC;AACzC,6BAA0C;AAC1C,0BAAuC;AAEvC,gCAA4C;AAC5C,gCAA4C;AAC5C,0BAAuC;AACvC,yBAAsC;AACtC,4BAAyC;AACzC,yBAAsC;AACtC,8BAA2C;AAC3C,uBAAoC;AAEpC,6BAA0B;AAE1B,gCAA8B;AAC9B,4BAA2B;AAiB3B,wBAAc,8BA1Cd;","names":[]}
|
package/dist/lib/auth.d.mts
CHANGED
|
@@ -1,13 +1,23 @@
|
|
|
1
1
|
import { StackClientInterface } from '@stackframe/stack-shared';
|
|
2
|
+
import { InternalSession } from '@stackframe/stack-shared/dist/sessions';
|
|
2
3
|
|
|
3
|
-
declare function signInWithOAuth(iface: StackClientInterface,
|
|
4
|
+
declare function signInWithOAuth(iface: StackClientInterface, options: {
|
|
4
5
|
provider: string;
|
|
5
|
-
redirectUrl
|
|
6
|
+
redirectUrl: string;
|
|
7
|
+
errorRedirectUrl: string;
|
|
8
|
+
providerScope?: string;
|
|
6
9
|
}): Promise<void>;
|
|
10
|
+
declare function addNewOAuthProviderOrScope(iface: StackClientInterface, options: {
|
|
11
|
+
provider: string;
|
|
12
|
+
redirectUrl: string;
|
|
13
|
+
errorRedirectUrl: string;
|
|
14
|
+
providerScope?: string;
|
|
15
|
+
}, session: InternalSession): Promise<void>;
|
|
7
16
|
declare function callOAuthCallback(iface: StackClientInterface, redirectUrl: string): Promise<{
|
|
8
17
|
newUser: boolean;
|
|
18
|
+
afterCallbackRedirectUrl?: string | undefined;
|
|
9
19
|
accessToken: string;
|
|
10
20
|
refreshToken: string;
|
|
11
21
|
} | null>;
|
|
12
22
|
|
|
13
|
-
export { callOAuthCallback, signInWithOAuth };
|
|
23
|
+
export { addNewOAuthProviderOrScope, callOAuthCallback, signInWithOAuth };
|
package/dist/lib/auth.d.ts
CHANGED
|
@@ -1,13 +1,23 @@
|
|
|
1
1
|
import { StackClientInterface } from '@stackframe/stack-shared';
|
|
2
|
+
import { InternalSession } from '@stackframe/stack-shared/dist/sessions';
|
|
2
3
|
|
|
3
|
-
declare function signInWithOAuth(iface: StackClientInterface,
|
|
4
|
+
declare function signInWithOAuth(iface: StackClientInterface, options: {
|
|
4
5
|
provider: string;
|
|
5
|
-
redirectUrl
|
|
6
|
+
redirectUrl: string;
|
|
7
|
+
errorRedirectUrl: string;
|
|
8
|
+
providerScope?: string;
|
|
6
9
|
}): Promise<void>;
|
|
10
|
+
declare function addNewOAuthProviderOrScope(iface: StackClientInterface, options: {
|
|
11
|
+
provider: string;
|
|
12
|
+
redirectUrl: string;
|
|
13
|
+
errorRedirectUrl: string;
|
|
14
|
+
providerScope?: string;
|
|
15
|
+
}, session: InternalSession): Promise<void>;
|
|
7
16
|
declare function callOAuthCallback(iface: StackClientInterface, redirectUrl: string): Promise<{
|
|
8
17
|
newUser: boolean;
|
|
18
|
+
afterCallbackRedirectUrl?: string | undefined;
|
|
9
19
|
accessToken: string;
|
|
10
20
|
refreshToken: string;
|
|
11
21
|
} | null>;
|
|
12
22
|
|
|
13
|
-
export { callOAuthCallback, signInWithOAuth };
|
|
23
|
+
export { addNewOAuthProviderOrScope, callOAuthCallback, signInWithOAuth };
|
package/dist/lib/auth.js
CHANGED
|
@@ -20,6 +20,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
20
20
|
// src/lib/auth.ts
|
|
21
21
|
var auth_exports = {};
|
|
22
22
|
__export(auth_exports, {
|
|
23
|
+
addNewOAuthProviderOrScope: () => addNewOAuthProviderOrScope,
|
|
23
24
|
callOAuthCallback: () => callOAuthCallback,
|
|
24
25
|
signInWithOAuth: () => signInWithOAuth
|
|
25
26
|
});
|
|
@@ -28,18 +29,33 @@ var import_cookie = require("./cookie");
|
|
|
28
29
|
var import_url = require("../utils/url");
|
|
29
30
|
var import_promises = require("@stackframe/stack-shared/dist/utils/promises");
|
|
30
31
|
var import_errors = require("@stackframe/stack-shared/dist/utils/errors");
|
|
31
|
-
async function signInWithOAuth(iface, {
|
|
32
|
-
provider,
|
|
33
|
-
redirectUrl
|
|
34
|
-
}) {
|
|
35
|
-
redirectUrl = (0, import_url.constructRedirectUrl)(redirectUrl);
|
|
32
|
+
async function signInWithOAuth(iface, options) {
|
|
36
33
|
const { codeChallenge, state } = await (0, import_cookie.saveVerifierAndState)();
|
|
37
|
-
const location = await iface.getOAuthUrl(
|
|
38
|
-
provider,
|
|
39
|
-
redirectUrl,
|
|
34
|
+
const location = await iface.getOAuthUrl({
|
|
35
|
+
provider: options.provider,
|
|
36
|
+
redirectUrl: (0, import_url.constructRedirectUrl)(options.redirectUrl),
|
|
37
|
+
errorRedirectUrl: (0, import_url.constructRedirectUrl)(options.errorRedirectUrl),
|
|
40
38
|
codeChallenge,
|
|
41
|
-
state
|
|
42
|
-
|
|
39
|
+
state,
|
|
40
|
+
type: "authenticate",
|
|
41
|
+
providerScope: options.providerScope
|
|
42
|
+
});
|
|
43
|
+
window.location.assign(location);
|
|
44
|
+
await (0, import_promises.neverResolve)();
|
|
45
|
+
}
|
|
46
|
+
async function addNewOAuthProviderOrScope(iface, options, session) {
|
|
47
|
+
const { codeChallenge, state } = await (0, import_cookie.saveVerifierAndState)();
|
|
48
|
+
const location = await iface.getOAuthUrl({
|
|
49
|
+
provider: options.provider,
|
|
50
|
+
redirectUrl: (0, import_url.constructRedirectUrl)(options.redirectUrl),
|
|
51
|
+
errorRedirectUrl: (0, import_url.constructRedirectUrl)(options.errorRedirectUrl),
|
|
52
|
+
afterCallbackRedirectUrl: (0, import_url.constructRedirectUrl)(window.location.href),
|
|
53
|
+
codeChallenge,
|
|
54
|
+
state,
|
|
55
|
+
type: "link",
|
|
56
|
+
session,
|
|
57
|
+
providerScope: options.providerScope
|
|
58
|
+
});
|
|
43
59
|
window.location.assign(location);
|
|
44
60
|
await (0, import_promises.neverResolve)();
|
|
45
61
|
}
|
|
@@ -70,18 +86,19 @@ async function callOAuthCallback(iface, redirectUrl) {
|
|
|
70
86
|
if (!originalUrl)
|
|
71
87
|
return null;
|
|
72
88
|
try {
|
|
73
|
-
return await iface.callOAuthCallback(
|
|
74
|
-
originalUrl.searchParams,
|
|
75
|
-
(0, import_url.constructRedirectUrl)(redirectUrl),
|
|
89
|
+
return await iface.callOAuthCallback({
|
|
90
|
+
oauthParams: originalUrl.searchParams,
|
|
91
|
+
redirectUri: (0, import_url.constructRedirectUrl)(redirectUrl),
|
|
76
92
|
codeVerifier,
|
|
77
93
|
state
|
|
78
|
-
);
|
|
94
|
+
});
|
|
79
95
|
} catch (e) {
|
|
80
96
|
throw new import_errors.StackAssertionError("Error signing in during OAuth callback. Please try again.", { cause: e });
|
|
81
97
|
}
|
|
82
98
|
}
|
|
83
99
|
// Annotate the CommonJS export names for ESM import in node:
|
|
84
100
|
0 && (module.exports = {
|
|
101
|
+
addNewOAuthProviderOrScope,
|
|
85
102
|
callOAuthCallback,
|
|
86
103
|
signInWithOAuth
|
|
87
104
|
});
|
package/dist/lib/auth.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/lib/auth.ts"],"sourcesContent":["import { StackClientInterface } from \"@stackframe/stack-shared\";\nimport { saveVerifierAndState, getVerifierAndState } from \"./cookie\";\nimport { constructRedirectUrl } from \"../utils/url\";\nimport { neverResolve
|
|
1
|
+
{"version":3,"sources":["../../src/lib/auth.ts"],"sourcesContent":["import { StackClientInterface } from \"@stackframe/stack-shared\";\nimport { saveVerifierAndState, getVerifierAndState } from \"./cookie\";\nimport { constructRedirectUrl } from \"../utils/url\";\nimport { neverResolve } from \"@stackframe/stack-shared/dist/utils/promises\";\nimport { StackAssertionError } from \"@stackframe/stack-shared/dist/utils/errors\";\nimport { InternalSession } from \"@stackframe/stack-shared/dist/sessions\";\n\nexport async function signInWithOAuth(\n iface: StackClientInterface,\n options: { \n provider: string,\n redirectUrl: string,\n errorRedirectUrl: string,\n providerScope?: string,\n }\n) {\n const { codeChallenge, state } = await saveVerifierAndState();\n const location = await iface.getOAuthUrl({\n provider: options.provider,\n redirectUrl: constructRedirectUrl(options.redirectUrl),\n errorRedirectUrl: constructRedirectUrl(options.errorRedirectUrl),\n codeChallenge,\n state,\n type: \"authenticate\",\n providerScope: options.providerScope,\n });\n window.location.assign(location);\n await neverResolve();\n}\n\nexport async function addNewOAuthProviderOrScope(\n iface: StackClientInterface,\n options: { \n provider: string,\n redirectUrl: string,\n errorRedirectUrl: string,\n providerScope?: string,\n },\n session: InternalSession,\n) {\n const { codeChallenge, state } = await saveVerifierAndState();\n const location = await iface.getOAuthUrl({\n provider: options.provider,\n redirectUrl: constructRedirectUrl(options.redirectUrl),\n errorRedirectUrl: constructRedirectUrl(options.errorRedirectUrl),\n afterCallbackRedirectUrl: constructRedirectUrl(window.location.href),\n codeChallenge,\n state,\n type: \"link\",\n session,\n providerScope: options.providerScope,\n });\n window.location.assign(location);\n await neverResolve();\n}\n\n/**\n * Checks if the current URL has the query parameters for an OAuth callback, and if so, removes them.\n * \n * Must be synchronous for the logic in callOAuthCallback to work without race conditions.\n */\nfunction consumeOAuthCallbackQueryParams(expectedState: string): null | URL {\n const requiredParams = [\"code\", \"state\"];\n const originalUrl = new URL(window.location.href);\n for (const param of requiredParams) {\n if (!originalUrl.searchParams.has(param)) {\n return null;\n }\n }\n\n if (expectedState !== originalUrl.searchParams.get(\"state\")) {\n // If the state doesn't match, then the callback wasn't meant for us.\n // Maybe the website uses another OAuth library?\n return null;\n }\n\n\n const newUrl = new URL(originalUrl);\n for (const param of requiredParams) {\n newUrl.searchParams.delete(param);\n }\n\n // let's get rid of the authorization code in the history as we\n // don't redirect to `redirectUrl` if there's a validation error\n // (as the redirectUrl might be malicious!).\n //\n // We use history.replaceState instead of location.assign(...) to\n // prevent an unnecessary reload\n window.history.replaceState({}, \"\", newUrl.toString());\n\n return originalUrl; \n}\n\nexport async function callOAuthCallback(\n iface: StackClientInterface,\n redirectUrl: string,\n) {\n // note: this part of the function (until the return) needs\n // to be synchronous, to prevent race conditions when\n // callOAuthCallback is called multiple times in parallel\n const { codeVerifier, state } = getVerifierAndState();\n if (!codeVerifier || !state) {\n throw new Error(\"Invalid OAuth callback URL parameters. It seems like the OAuth flow was interrupted, so please try again.\");\n }\n const originalUrl = consumeOAuthCallbackQueryParams(state);\n if (!originalUrl) return null;\n\n // the rest can be asynchronous (we now know that we are the\n // intended recipient of the callback)\n try {\n return await iface.callOAuthCallback({\n oauthParams: originalUrl.searchParams,\n redirectUri: constructRedirectUrl(redirectUrl),\n codeVerifier,\n state,\n });\n } catch (e) {\n throw new StackAssertionError(\"Error signing in during OAuth callback. Please try again.\", { cause: e });\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,oBAA0D;AAC1D,iBAAqC;AACrC,sBAA6B;AAC7B,oBAAoC;AAGpC,eAAsB,gBACpB,OACA,SAMA;AACA,QAAM,EAAE,eAAe,MAAM,IAAI,UAAM,oCAAqB;AAC5D,QAAM,WAAW,MAAM,MAAM,YAAY;AAAA,IACvC,UAAU,QAAQ;AAAA,IAClB,iBAAa,iCAAqB,QAAQ,WAAW;AAAA,IACrD,sBAAkB,iCAAqB,QAAQ,gBAAgB;AAAA,IAC/D;AAAA,IACA;AAAA,IACA,MAAM;AAAA,IACN,eAAe,QAAQ;AAAA,EACzB,CAAC;AACD,SAAO,SAAS,OAAO,QAAQ;AAC/B,YAAM,8BAAa;AACrB;AAEA,eAAsB,2BACpB,OACA,SAMA,SACA;AACA,QAAM,EAAE,eAAe,MAAM,IAAI,UAAM,oCAAqB;AAC5D,QAAM,WAAW,MAAM,MAAM,YAAY;AAAA,IACvC,UAAU,QAAQ;AAAA,IAClB,iBAAa,iCAAqB,QAAQ,WAAW;AAAA,IACrD,sBAAkB,iCAAqB,QAAQ,gBAAgB;AAAA,IAC/D,8BAA0B,iCAAqB,OAAO,SAAS,IAAI;AAAA,IACnE;AAAA,IACA;AAAA,IACA,MAAM;AAAA,IACN;AAAA,IACA,eAAe,QAAQ;AAAA,EACzB,CAAC;AACD,SAAO,SAAS,OAAO,QAAQ;AAC/B,YAAM,8BAAa;AACrB;AAOA,SAAS,gCAAgC,eAAmC;AAC1E,QAAM,iBAAiB,CAAC,QAAQ,OAAO;AACvC,QAAM,cAAc,IAAI,IAAI,OAAO,SAAS,IAAI;AAChD,aAAW,SAAS,gBAAgB;AAClC,QAAI,CAAC,YAAY,aAAa,IAAI,KAAK,GAAG;AACxC,aAAO;AAAA,IACT;AAAA,EACF;AAEA,MAAI,kBAAkB,YAAY,aAAa,IAAI,OAAO,GAAG;AAG3D,WAAO;AAAA,EACT;AAGA,QAAM,SAAS,IAAI,IAAI,WAAW;AAClC,aAAW,SAAS,gBAAgB;AAClC,WAAO,aAAa,OAAO,KAAK;AAAA,EAClC;AAQA,SAAO,QAAQ,aAAa,CAAC,GAAG,IAAI,OAAO,SAAS,CAAC;AAErD,SAAO;AACT;AAEA,eAAsB,kBACpB,OACA,aACA;AAIA,QAAM,EAAE,cAAc,MAAM,QAAI,mCAAoB;AACpD,MAAI,CAAC,gBAAgB,CAAC,OAAO;AAC3B,UAAM,IAAI,MAAM,2GAA2G;AAAA,EAC7H;AACA,QAAM,cAAc,gCAAgC,KAAK;AACzD,MAAI,CAAC;AAAa,WAAO;AAIzB,MAAI;AACF,WAAO,MAAM,MAAM,kBAAkB;AAAA,MACnC,aAAa,YAAY;AAAA,MACzB,iBAAa,iCAAqB,WAAW;AAAA,MAC7C;AAAA,MACA;AAAA,IACF,CAAC;AAAA,EACH,SAAS,GAAG;AACV,UAAM,IAAI,kCAAoB,6DAA6D,EAAE,OAAO,EAAE,CAAC;AAAA,EACzG;AACF;","names":[]}
|
package/dist/lib/stack-app.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ServerUserJson, OAuthProviderConfigJson, KnownErrors } from '@stackframe/stack-shared';
|
|
2
|
-
import { UserJson, UserUpdateJson, ProjectJson, ProductionModeError, TeamJson, EmailConfigJson, DomainConfigJson, ClientProjectJson } from '@stackframe/stack-shared/dist/interface/clientInterface';
|
|
2
|
+
import { StandardProvider, UserJson, UserUpdateJson, ProjectJson, ProductionModeError, TeamJson, EmailConfigJson, DomainConfigJson, ClientProjectJson } from '@stackframe/stack-shared/dist/interface/clientInterface';
|
|
3
3
|
import { ReadonlyJson } from '@stackframe/stack-shared/dist/utils/json';
|
|
4
4
|
import { ProjectUpdateOptions, ApiKeySetCreateOptions } from '@stackframe/stack-shared/dist/interface/adminInterface';
|
|
5
5
|
import { ServerUserUpdateJson, ServerTeamCustomizableJson, ServerPermissionDefinitionCustomizableJson, ServerPermissionDefinitionJson, EmailTemplateType } from '@stackframe/stack-shared/dist/interface/serverInterface';
|
|
@@ -30,6 +30,10 @@ type HandlerUrls = {
|
|
|
30
30
|
oauthCallback: string;
|
|
31
31
|
magicLinkCallback: string;
|
|
32
32
|
accountSettings: string;
|
|
33
|
+
error: string;
|
|
34
|
+
};
|
|
35
|
+
type OAuthScopesOnSignIn = {
|
|
36
|
+
[key in StandardProvider]: string[];
|
|
33
37
|
};
|
|
34
38
|
type ProjectCurrentUser<ProjectId> = ProjectId extends "internal" ? CurrentInternalUser : CurrentUser;
|
|
35
39
|
type StackClientAppConstructorOptions<HasTokenStore extends boolean, ProjectId extends string> = {
|
|
@@ -37,6 +41,7 @@ type StackClientAppConstructorOptions<HasTokenStore extends boolean, ProjectId e
|
|
|
37
41
|
projectId?: ProjectId;
|
|
38
42
|
publishableClientKey?: string;
|
|
39
43
|
urls?: Partial<HandlerUrls>;
|
|
44
|
+
oauthScopesOnSignIn?: Partial<OAuthScopesOnSignIn>;
|
|
40
45
|
tokenStore: TokenStoreInit<HasTokenStore>;
|
|
41
46
|
};
|
|
42
47
|
type StackServerAppConstructorOptions<HasTokenStore extends boolean, ProjectId extends string> = StackClientAppConstructorOptions<HasTokenStore, ProjectId> & {
|
|
@@ -67,6 +72,77 @@ type Auth<T, C> = {
|
|
|
67
72
|
readonly _internalSession: InternalSession;
|
|
68
73
|
readonly currentSession: Session;
|
|
69
74
|
signOut(this: T): Promise<void>;
|
|
75
|
+
/**
|
|
76
|
+
* Returns headers for sending authenticated HTTP requests to external servers. Most commonly used in cross-origin
|
|
77
|
+
* requests. Similar to `getAuthJson`, but specifically for HTTP requests.
|
|
78
|
+
*
|
|
79
|
+
* If you are using `tokenStore: "cookie"`, you don't need this for same-origin requests. However, most
|
|
80
|
+
* browsers now disable third-party cookies by default, so we must pass authentication tokens by header instead
|
|
81
|
+
* if the client and server are on different hostnames.
|
|
82
|
+
*
|
|
83
|
+
* This function returns a header object that can be used with `fetch` or other HTTP request libraries to send
|
|
84
|
+
* authenticated requests.
|
|
85
|
+
*
|
|
86
|
+
* On the server, you can then pass in the `Request` object to the `tokenStore` option
|
|
87
|
+
* of your Stack app. Please note that CORS does not allow most headers by default, so you
|
|
88
|
+
* must include `x-stack-auth` in the [`Access-Control-Allow-Headers` header](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Access-Control-Allow-Headers)
|
|
89
|
+
* of the CORS preflight response.
|
|
90
|
+
*
|
|
91
|
+
* If you are not using HTTP (and hence cannot set headers), you will need to use the `getAuthJson()` function
|
|
92
|
+
* instead.
|
|
93
|
+
*
|
|
94
|
+
* Example:
|
|
95
|
+
*
|
|
96
|
+
* ```ts
|
|
97
|
+
* // client
|
|
98
|
+
* const res = await fetch("https://api.example.com", {
|
|
99
|
+
* headers: {
|
|
100
|
+
* ...await stackApp.getAuthHeaders()
|
|
101
|
+
* // you can also add your own headers here
|
|
102
|
+
* },
|
|
103
|
+
* });
|
|
104
|
+
*
|
|
105
|
+
* // server
|
|
106
|
+
* function handleRequest(req: Request) {
|
|
107
|
+
* const user = await stackServerApp.getUser({ tokenStore: req });
|
|
108
|
+
* return new Response("Welcome, " + user.displayName);
|
|
109
|
+
* }
|
|
110
|
+
* ```
|
|
111
|
+
*/
|
|
112
|
+
getAuthHeaders(): Promise<{
|
|
113
|
+
"x-stack-auth": string;
|
|
114
|
+
}>;
|
|
115
|
+
/**
|
|
116
|
+
* Creates a JSON-serializable object containing the information to authenticate a user on an external server.
|
|
117
|
+
* Similar to `getAuthHeaders`, but returns an object that can be sent over any protocol instead of just
|
|
118
|
+
* HTTP headers.
|
|
119
|
+
*
|
|
120
|
+
* While `getAuthHeaders` is the recommended way to send authentication tokens over HTTP, your app may use
|
|
121
|
+
* a different protocol, for example WebSockets or gRPC. This function returns a token object that can be JSON-serialized and sent to the server in any way you like.
|
|
122
|
+
*
|
|
123
|
+
* On the server, you can pass in this token object into the `tokenStore` option to fetch user details.
|
|
124
|
+
*
|
|
125
|
+
* Example:
|
|
126
|
+
*
|
|
127
|
+
* ```ts
|
|
128
|
+
* // client
|
|
129
|
+
* const res = await rpcCall(rpcEndpoint, {
|
|
130
|
+
* data: {
|
|
131
|
+
* auth: await stackApp.getAuthJson(),
|
|
132
|
+
* },
|
|
133
|
+
* });
|
|
134
|
+
*
|
|
135
|
+
* // server
|
|
136
|
+
* function handleRequest(data) {
|
|
137
|
+
* const user = await stackServerApp.getUser({ tokenStore: data.auth });
|
|
138
|
+
* return new Response("Welcome, " + user.displayName);
|
|
139
|
+
* }
|
|
140
|
+
* ```
|
|
141
|
+
*/
|
|
142
|
+
getAuthJson(): Promise<{
|
|
143
|
+
accessToken: string | null;
|
|
144
|
+
refreshToken: string | null;
|
|
145
|
+
}>;
|
|
70
146
|
update(this: T, user: C): Promise<void>;
|
|
71
147
|
updateSelectedTeam(this: T, team: Team | null): Promise<void>;
|
|
72
148
|
sendVerificationEmail(this: T): Promise<KnownErrors["EmailAlreadyVerified"] | void>;
|
|
@@ -104,6 +180,28 @@ type User = ({
|
|
|
104
180
|
hasPermission(this: CurrentUser, scope: Team, permissionId: string): Promise<boolean>;
|
|
105
181
|
getSelectedTeam(this: CurrentUser): Promise<Team | null>;
|
|
106
182
|
useSelectedTeam(this: CurrentUser): Team | null;
|
|
183
|
+
getConnection(id: StandardProvider, options?: {
|
|
184
|
+
scopes?: string[];
|
|
185
|
+
}): Promise<OAuthConnection | null>;
|
|
186
|
+
getConnection(id: StandardProvider, options: {
|
|
187
|
+
or: 'redirect';
|
|
188
|
+
scopes?: string[];
|
|
189
|
+
}): Promise<OAuthConnection>;
|
|
190
|
+
getConnection(id: StandardProvider, options?: {
|
|
191
|
+
or?: 'redirect';
|
|
192
|
+
scopes?: string[];
|
|
193
|
+
}): Promise<OAuthConnection | null>;
|
|
194
|
+
useConnection(id: StandardProvider, options?: {
|
|
195
|
+
scopes?: string[];
|
|
196
|
+
}): OAuthConnection | null;
|
|
197
|
+
useConnection(id: StandardProvider, options: {
|
|
198
|
+
or: 'redirect';
|
|
199
|
+
scopes?: string[];
|
|
200
|
+
}): OAuthConnection;
|
|
201
|
+
useConnection(id: StandardProvider, options?: {
|
|
202
|
+
or?: 'redirect';
|
|
203
|
+
scopes?: string[];
|
|
204
|
+
}): OAuthConnection | null;
|
|
107
205
|
toJson(this: CurrentUser): UserJson;
|
|
108
206
|
} & AsyncStoreProperty<"team", [id: string], Team | null, false> & AsyncStoreProperty<"teams", [], Team[], true> & Omit<AsyncStoreProperty<"permission", [scope: Team, permissionId: string, options?: {
|
|
109
207
|
direct?: boolean;
|
|
@@ -193,6 +291,17 @@ type ServerPermission = Permission & {
|
|
|
193
291
|
readonly description?: string;
|
|
194
292
|
readonly containPermissionIds: string[];
|
|
195
293
|
};
|
|
294
|
+
type Connection = {
|
|
295
|
+
id: string;
|
|
296
|
+
};
|
|
297
|
+
type OAuthConnection = Connection & {
|
|
298
|
+
getAccessToken(): Promise<{
|
|
299
|
+
accessToken: string;
|
|
300
|
+
}>;
|
|
301
|
+
useAccessToken(): {
|
|
302
|
+
accessToken: string;
|
|
303
|
+
};
|
|
304
|
+
};
|
|
196
305
|
type ApiKeySetBase = {
|
|
197
306
|
id: string;
|
|
198
307
|
description: string;
|
|
@@ -262,69 +371,6 @@ type StackClientApp<HasTokenStore extends boolean = boolean, ProjectId extends s
|
|
|
262
371
|
verifyPasswordResetCode(code: string): Promise<KnownErrors["PasswordResetCodeError"] | void>;
|
|
263
372
|
verifyEmail(code: string): Promise<KnownErrors["EmailVerificationError"] | void>;
|
|
264
373
|
signInWithMagicLink(code: string): Promise<KnownErrors["MagicLinkError"] | void>;
|
|
265
|
-
/**
|
|
266
|
-
* With most browsers now disabling third-party cookies by default, the best way to send authenticated requests
|
|
267
|
-
* across different origins is to pass the tokens in a header.
|
|
268
|
-
*
|
|
269
|
-
* This function returns a header object that can be used with `fetch` or other HTTP request libraries to send
|
|
270
|
-
* authenticated requests.
|
|
271
|
-
*
|
|
272
|
-
* On the server, you can then pass in the `Request` object to the `tokenStore` option
|
|
273
|
-
* on your Stack app to fetch user details. Please note that CORS by default does not allow custom headers, so you
|
|
274
|
-
* must set the [`Access-Control-Allow-Headers` header](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Access-Control-Allow-Headers)
|
|
275
|
-
* to include `x-stack-auth` in the CORS preflight response.
|
|
276
|
-
*
|
|
277
|
-
* Example:
|
|
278
|
-
*
|
|
279
|
-
* ```ts
|
|
280
|
-
* // client
|
|
281
|
-
* const res = await fetch("https://api.example.com", {
|
|
282
|
-
* headers: {
|
|
283
|
-
* ...await stackApp.getCrossOriginHeaders()
|
|
284
|
-
* // you can also add your own headers here
|
|
285
|
-
* },
|
|
286
|
-
* });
|
|
287
|
-
*
|
|
288
|
-
* // server
|
|
289
|
-
* function handleRequest(req: Request) {
|
|
290
|
-
* const user = await stackServerApp.getUser({ tokenStore: req });
|
|
291
|
-
* return new Response("Welcome, " + user.displayName);
|
|
292
|
-
* }
|
|
293
|
-
* ```
|
|
294
|
-
*/
|
|
295
|
-
getCrossOriginHeaders(): Promise<{
|
|
296
|
-
"x-stack-auth": string;
|
|
297
|
-
}>;
|
|
298
|
-
/**
|
|
299
|
-
* With most browsers now disabling third-party cookies by default, there need to be new ways to send authenticated
|
|
300
|
-
* requests across different origins. While `getCrossOriginHeaders` is the recommended way to do this, there
|
|
301
|
-
* are some cases where you might want to send the tokens differently, for example when you are using WebSockets
|
|
302
|
-
* or non-HTTP protocols.
|
|
303
|
-
*
|
|
304
|
-
* This function returns a token object that can be JSON-serialized and sent to the server in any way you like.
|
|
305
|
-
* There, you can use the `tokenStore` option on your Stack app to fetch user details.
|
|
306
|
-
*
|
|
307
|
-
* Example:
|
|
308
|
-
*
|
|
309
|
-
* ```ts
|
|
310
|
-
* // client
|
|
311
|
-
* const res = await rpcCall(rpcEndpoint, {
|
|
312
|
-
* data: {
|
|
313
|
-
* auth: await stackApp.getCrossOriginTokenObject(),
|
|
314
|
-
* },
|
|
315
|
-
* });
|
|
316
|
-
*
|
|
317
|
-
* // server
|
|
318
|
-
* function handleRequest(data) {
|
|
319
|
-
* const user = await stackServerApp.getUser({ tokenStore: data.auth });
|
|
320
|
-
* return new Response("Welcome, " + user.displayName);
|
|
321
|
-
* }
|
|
322
|
-
* ```
|
|
323
|
-
*/
|
|
324
|
-
getCrossOriginTokenObject(): Promise<{
|
|
325
|
-
accessToken: string | null;
|
|
326
|
-
refreshToken: string | null;
|
|
327
|
-
}>;
|
|
328
374
|
[stackAppInternalsSymbol]: {
|
|
329
375
|
toClientJson(): StackClientAppJson<HasTokenStore, ProjectId>;
|
|
330
376
|
setCurrentUser(userJsonPromise: Promise<UserJson | null>): void;
|
|
@@ -376,4 +422,4 @@ type StackAdminApp<HasTokenStore extends boolean = boolean, ProjectId extends st
|
|
|
376
422
|
});
|
|
377
423
|
declare const StackAdminApp: StackAdminAppConstructor;
|
|
378
424
|
|
|
379
|
-
export { type ApiKeySet, type ApiKeySetBase, type ApiKeySetFirstView, type CurrentInternalServerUser, type CurrentInternalUser, type CurrentServerUser, type CurrentUser, type DomainConfig, type EmailConfig, type GetUserOptions, type HandlerUrls, type OAuthProviderConfig, type Permission, type Project, type ServerPermission, type ServerTeam, type ServerTeamMember, type ServerUser, StackAdminApp, type StackAdminAppConstructorOptions, StackClientApp, type StackClientAppConstructorOptions, type StackClientAppJson, StackServerApp, type StackServerAppConstructorOptions, type Team, type TeamMember, type TokenStoreInit, type User, stackAppInternalsSymbol };
|
|
425
|
+
export { type ApiKeySet, type ApiKeySetBase, type ApiKeySetFirstView, type Connection, type CurrentInternalServerUser, type CurrentInternalUser, type CurrentServerUser, type CurrentUser, type DomainConfig, type EmailConfig, type GetUserOptions, type HandlerUrls, type OAuthConnection, type OAuthProviderConfig, type OAuthScopesOnSignIn, type Permission, type Project, type ServerPermission, type ServerTeam, type ServerTeamMember, type ServerUser, StackAdminApp, type StackAdminAppConstructorOptions, StackClientApp, type StackClientAppConstructorOptions, type StackClientAppJson, StackServerApp, type StackServerAppConstructorOptions, type Team, type TeamMember, type TokenStoreInit, type User, stackAppInternalsSymbol };
|
package/dist/lib/stack-app.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ServerUserJson, OAuthProviderConfigJson, KnownErrors } from '@stackframe/stack-shared';
|
|
2
|
-
import { UserJson, UserUpdateJson, ProjectJson, ProductionModeError, TeamJson, EmailConfigJson, DomainConfigJson, ClientProjectJson } from '@stackframe/stack-shared/dist/interface/clientInterface';
|
|
2
|
+
import { StandardProvider, UserJson, UserUpdateJson, ProjectJson, ProductionModeError, TeamJson, EmailConfigJson, DomainConfigJson, ClientProjectJson } from '@stackframe/stack-shared/dist/interface/clientInterface';
|
|
3
3
|
import { ReadonlyJson } from '@stackframe/stack-shared/dist/utils/json';
|
|
4
4
|
import { ProjectUpdateOptions, ApiKeySetCreateOptions } from '@stackframe/stack-shared/dist/interface/adminInterface';
|
|
5
5
|
import { ServerUserUpdateJson, ServerTeamCustomizableJson, ServerPermissionDefinitionCustomizableJson, ServerPermissionDefinitionJson, EmailTemplateType } from '@stackframe/stack-shared/dist/interface/serverInterface';
|
|
@@ -30,6 +30,10 @@ type HandlerUrls = {
|
|
|
30
30
|
oauthCallback: string;
|
|
31
31
|
magicLinkCallback: string;
|
|
32
32
|
accountSettings: string;
|
|
33
|
+
error: string;
|
|
34
|
+
};
|
|
35
|
+
type OAuthScopesOnSignIn = {
|
|
36
|
+
[key in StandardProvider]: string[];
|
|
33
37
|
};
|
|
34
38
|
type ProjectCurrentUser<ProjectId> = ProjectId extends "internal" ? CurrentInternalUser : CurrentUser;
|
|
35
39
|
type StackClientAppConstructorOptions<HasTokenStore extends boolean, ProjectId extends string> = {
|
|
@@ -37,6 +41,7 @@ type StackClientAppConstructorOptions<HasTokenStore extends boolean, ProjectId e
|
|
|
37
41
|
projectId?: ProjectId;
|
|
38
42
|
publishableClientKey?: string;
|
|
39
43
|
urls?: Partial<HandlerUrls>;
|
|
44
|
+
oauthScopesOnSignIn?: Partial<OAuthScopesOnSignIn>;
|
|
40
45
|
tokenStore: TokenStoreInit<HasTokenStore>;
|
|
41
46
|
};
|
|
42
47
|
type StackServerAppConstructorOptions<HasTokenStore extends boolean, ProjectId extends string> = StackClientAppConstructorOptions<HasTokenStore, ProjectId> & {
|
|
@@ -67,6 +72,77 @@ type Auth<T, C> = {
|
|
|
67
72
|
readonly _internalSession: InternalSession;
|
|
68
73
|
readonly currentSession: Session;
|
|
69
74
|
signOut(this: T): Promise<void>;
|
|
75
|
+
/**
|
|
76
|
+
* Returns headers for sending authenticated HTTP requests to external servers. Most commonly used in cross-origin
|
|
77
|
+
* requests. Similar to `getAuthJson`, but specifically for HTTP requests.
|
|
78
|
+
*
|
|
79
|
+
* If you are using `tokenStore: "cookie"`, you don't need this for same-origin requests. However, most
|
|
80
|
+
* browsers now disable third-party cookies by default, so we must pass authentication tokens by header instead
|
|
81
|
+
* if the client and server are on different hostnames.
|
|
82
|
+
*
|
|
83
|
+
* This function returns a header object that can be used with `fetch` or other HTTP request libraries to send
|
|
84
|
+
* authenticated requests.
|
|
85
|
+
*
|
|
86
|
+
* On the server, you can then pass in the `Request` object to the `tokenStore` option
|
|
87
|
+
* of your Stack app. Please note that CORS does not allow most headers by default, so you
|
|
88
|
+
* must include `x-stack-auth` in the [`Access-Control-Allow-Headers` header](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Access-Control-Allow-Headers)
|
|
89
|
+
* of the CORS preflight response.
|
|
90
|
+
*
|
|
91
|
+
* If you are not using HTTP (and hence cannot set headers), you will need to use the `getAuthJson()` function
|
|
92
|
+
* instead.
|
|
93
|
+
*
|
|
94
|
+
* Example:
|
|
95
|
+
*
|
|
96
|
+
* ```ts
|
|
97
|
+
* // client
|
|
98
|
+
* const res = await fetch("https://api.example.com", {
|
|
99
|
+
* headers: {
|
|
100
|
+
* ...await stackApp.getAuthHeaders()
|
|
101
|
+
* // you can also add your own headers here
|
|
102
|
+
* },
|
|
103
|
+
* });
|
|
104
|
+
*
|
|
105
|
+
* // server
|
|
106
|
+
* function handleRequest(req: Request) {
|
|
107
|
+
* const user = await stackServerApp.getUser({ tokenStore: req });
|
|
108
|
+
* return new Response("Welcome, " + user.displayName);
|
|
109
|
+
* }
|
|
110
|
+
* ```
|
|
111
|
+
*/
|
|
112
|
+
getAuthHeaders(): Promise<{
|
|
113
|
+
"x-stack-auth": string;
|
|
114
|
+
}>;
|
|
115
|
+
/**
|
|
116
|
+
* Creates a JSON-serializable object containing the information to authenticate a user on an external server.
|
|
117
|
+
* Similar to `getAuthHeaders`, but returns an object that can be sent over any protocol instead of just
|
|
118
|
+
* HTTP headers.
|
|
119
|
+
*
|
|
120
|
+
* While `getAuthHeaders` is the recommended way to send authentication tokens over HTTP, your app may use
|
|
121
|
+
* a different protocol, for example WebSockets or gRPC. This function returns a token object that can be JSON-serialized and sent to the server in any way you like.
|
|
122
|
+
*
|
|
123
|
+
* On the server, you can pass in this token object into the `tokenStore` option to fetch user details.
|
|
124
|
+
*
|
|
125
|
+
* Example:
|
|
126
|
+
*
|
|
127
|
+
* ```ts
|
|
128
|
+
* // client
|
|
129
|
+
* const res = await rpcCall(rpcEndpoint, {
|
|
130
|
+
* data: {
|
|
131
|
+
* auth: await stackApp.getAuthJson(),
|
|
132
|
+
* },
|
|
133
|
+
* });
|
|
134
|
+
*
|
|
135
|
+
* // server
|
|
136
|
+
* function handleRequest(data) {
|
|
137
|
+
* const user = await stackServerApp.getUser({ tokenStore: data.auth });
|
|
138
|
+
* return new Response("Welcome, " + user.displayName);
|
|
139
|
+
* }
|
|
140
|
+
* ```
|
|
141
|
+
*/
|
|
142
|
+
getAuthJson(): Promise<{
|
|
143
|
+
accessToken: string | null;
|
|
144
|
+
refreshToken: string | null;
|
|
145
|
+
}>;
|
|
70
146
|
update(this: T, user: C): Promise<void>;
|
|
71
147
|
updateSelectedTeam(this: T, team: Team | null): Promise<void>;
|
|
72
148
|
sendVerificationEmail(this: T): Promise<KnownErrors["EmailAlreadyVerified"] | void>;
|
|
@@ -104,6 +180,28 @@ type User = ({
|
|
|
104
180
|
hasPermission(this: CurrentUser, scope: Team, permissionId: string): Promise<boolean>;
|
|
105
181
|
getSelectedTeam(this: CurrentUser): Promise<Team | null>;
|
|
106
182
|
useSelectedTeam(this: CurrentUser): Team | null;
|
|
183
|
+
getConnection(id: StandardProvider, options?: {
|
|
184
|
+
scopes?: string[];
|
|
185
|
+
}): Promise<OAuthConnection | null>;
|
|
186
|
+
getConnection(id: StandardProvider, options: {
|
|
187
|
+
or: 'redirect';
|
|
188
|
+
scopes?: string[];
|
|
189
|
+
}): Promise<OAuthConnection>;
|
|
190
|
+
getConnection(id: StandardProvider, options?: {
|
|
191
|
+
or?: 'redirect';
|
|
192
|
+
scopes?: string[];
|
|
193
|
+
}): Promise<OAuthConnection | null>;
|
|
194
|
+
useConnection(id: StandardProvider, options?: {
|
|
195
|
+
scopes?: string[];
|
|
196
|
+
}): OAuthConnection | null;
|
|
197
|
+
useConnection(id: StandardProvider, options: {
|
|
198
|
+
or: 'redirect';
|
|
199
|
+
scopes?: string[];
|
|
200
|
+
}): OAuthConnection;
|
|
201
|
+
useConnection(id: StandardProvider, options?: {
|
|
202
|
+
or?: 'redirect';
|
|
203
|
+
scopes?: string[];
|
|
204
|
+
}): OAuthConnection | null;
|
|
107
205
|
toJson(this: CurrentUser): UserJson;
|
|
108
206
|
} & AsyncStoreProperty<"team", [id: string], Team | null, false> & AsyncStoreProperty<"teams", [], Team[], true> & Omit<AsyncStoreProperty<"permission", [scope: Team, permissionId: string, options?: {
|
|
109
207
|
direct?: boolean;
|
|
@@ -193,6 +291,17 @@ type ServerPermission = Permission & {
|
|
|
193
291
|
readonly description?: string;
|
|
194
292
|
readonly containPermissionIds: string[];
|
|
195
293
|
};
|
|
294
|
+
type Connection = {
|
|
295
|
+
id: string;
|
|
296
|
+
};
|
|
297
|
+
type OAuthConnection = Connection & {
|
|
298
|
+
getAccessToken(): Promise<{
|
|
299
|
+
accessToken: string;
|
|
300
|
+
}>;
|
|
301
|
+
useAccessToken(): {
|
|
302
|
+
accessToken: string;
|
|
303
|
+
};
|
|
304
|
+
};
|
|
196
305
|
type ApiKeySetBase = {
|
|
197
306
|
id: string;
|
|
198
307
|
description: string;
|
|
@@ -262,69 +371,6 @@ type StackClientApp<HasTokenStore extends boolean = boolean, ProjectId extends s
|
|
|
262
371
|
verifyPasswordResetCode(code: string): Promise<KnownErrors["PasswordResetCodeError"] | void>;
|
|
263
372
|
verifyEmail(code: string): Promise<KnownErrors["EmailVerificationError"] | void>;
|
|
264
373
|
signInWithMagicLink(code: string): Promise<KnownErrors["MagicLinkError"] | void>;
|
|
265
|
-
/**
|
|
266
|
-
* With most browsers now disabling third-party cookies by default, the best way to send authenticated requests
|
|
267
|
-
* across different origins is to pass the tokens in a header.
|
|
268
|
-
*
|
|
269
|
-
* This function returns a header object that can be used with `fetch` or other HTTP request libraries to send
|
|
270
|
-
* authenticated requests.
|
|
271
|
-
*
|
|
272
|
-
* On the server, you can then pass in the `Request` object to the `tokenStore` option
|
|
273
|
-
* on your Stack app to fetch user details. Please note that CORS by default does not allow custom headers, so you
|
|
274
|
-
* must set the [`Access-Control-Allow-Headers` header](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Access-Control-Allow-Headers)
|
|
275
|
-
* to include `x-stack-auth` in the CORS preflight response.
|
|
276
|
-
*
|
|
277
|
-
* Example:
|
|
278
|
-
*
|
|
279
|
-
* ```ts
|
|
280
|
-
* // client
|
|
281
|
-
* const res = await fetch("https://api.example.com", {
|
|
282
|
-
* headers: {
|
|
283
|
-
* ...await stackApp.getCrossOriginHeaders()
|
|
284
|
-
* // you can also add your own headers here
|
|
285
|
-
* },
|
|
286
|
-
* });
|
|
287
|
-
*
|
|
288
|
-
* // server
|
|
289
|
-
* function handleRequest(req: Request) {
|
|
290
|
-
* const user = await stackServerApp.getUser({ tokenStore: req });
|
|
291
|
-
* return new Response("Welcome, " + user.displayName);
|
|
292
|
-
* }
|
|
293
|
-
* ```
|
|
294
|
-
*/
|
|
295
|
-
getCrossOriginHeaders(): Promise<{
|
|
296
|
-
"x-stack-auth": string;
|
|
297
|
-
}>;
|
|
298
|
-
/**
|
|
299
|
-
* With most browsers now disabling third-party cookies by default, there need to be new ways to send authenticated
|
|
300
|
-
* requests across different origins. While `getCrossOriginHeaders` is the recommended way to do this, there
|
|
301
|
-
* are some cases where you might want to send the tokens differently, for example when you are using WebSockets
|
|
302
|
-
* or non-HTTP protocols.
|
|
303
|
-
*
|
|
304
|
-
* This function returns a token object that can be JSON-serialized and sent to the server in any way you like.
|
|
305
|
-
* There, you can use the `tokenStore` option on your Stack app to fetch user details.
|
|
306
|
-
*
|
|
307
|
-
* Example:
|
|
308
|
-
*
|
|
309
|
-
* ```ts
|
|
310
|
-
* // client
|
|
311
|
-
* const res = await rpcCall(rpcEndpoint, {
|
|
312
|
-
* data: {
|
|
313
|
-
* auth: await stackApp.getCrossOriginTokenObject(),
|
|
314
|
-
* },
|
|
315
|
-
* });
|
|
316
|
-
*
|
|
317
|
-
* // server
|
|
318
|
-
* function handleRequest(data) {
|
|
319
|
-
* const user = await stackServerApp.getUser({ tokenStore: data.auth });
|
|
320
|
-
* return new Response("Welcome, " + user.displayName);
|
|
321
|
-
* }
|
|
322
|
-
* ```
|
|
323
|
-
*/
|
|
324
|
-
getCrossOriginTokenObject(): Promise<{
|
|
325
|
-
accessToken: string | null;
|
|
326
|
-
refreshToken: string | null;
|
|
327
|
-
}>;
|
|
328
374
|
[stackAppInternalsSymbol]: {
|
|
329
375
|
toClientJson(): StackClientAppJson<HasTokenStore, ProjectId>;
|
|
330
376
|
setCurrentUser(userJsonPromise: Promise<UserJson | null>): void;
|
|
@@ -376,4 +422,4 @@ type StackAdminApp<HasTokenStore extends boolean = boolean, ProjectId extends st
|
|
|
376
422
|
});
|
|
377
423
|
declare const StackAdminApp: StackAdminAppConstructor;
|
|
378
424
|
|
|
379
|
-
export { type ApiKeySet, type ApiKeySetBase, type ApiKeySetFirstView, type CurrentInternalServerUser, type CurrentInternalUser, type CurrentServerUser, type CurrentUser, type DomainConfig, type EmailConfig, type GetUserOptions, type HandlerUrls, type OAuthProviderConfig, type Permission, type Project, type ServerPermission, type ServerTeam, type ServerTeamMember, type ServerUser, StackAdminApp, type StackAdminAppConstructorOptions, StackClientApp, type StackClientAppConstructorOptions, type StackClientAppJson, StackServerApp, type StackServerAppConstructorOptions, type Team, type TeamMember, type TokenStoreInit, type User, stackAppInternalsSymbol };
|
|
425
|
+
export { type ApiKeySet, type ApiKeySetBase, type ApiKeySetFirstView, type Connection, type CurrentInternalServerUser, type CurrentInternalUser, type CurrentServerUser, type CurrentUser, type DomainConfig, type EmailConfig, type GetUserOptions, type HandlerUrls, type OAuthConnection, type OAuthProviderConfig, type OAuthScopesOnSignIn, type Permission, type Project, type ServerPermission, type ServerTeam, type ServerTeamMember, type ServerUser, StackAdminApp, type StackAdminAppConstructorOptions, StackClientApp, type StackClientAppConstructorOptions, type StackClientAppJson, StackServerApp, type StackServerAppConstructorOptions, type Team, type TeamMember, type TokenStoreInit, type User, stackAppInternalsSymbol };
|