@passflow/core 0.0.1 → 0.2.0
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/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +3174 -574
- package/dist/index.mjs.map +1 -1
- package/dist/lib/api/app.d.ts +4 -1
- package/dist/lib/api/app.d.ts.map +1 -1
- package/dist/lib/api/auth.d.ts +6 -4
- package/dist/lib/api/auth.d.ts.map +1 -1
- package/dist/lib/api/axios-client.d.ts +26 -4
- package/dist/lib/api/axios-client.d.ts.map +1 -1
- package/dist/lib/api/index.d.ts +4 -3
- package/dist/lib/api/index.d.ts.map +1 -1
- package/dist/lib/api/invitation.d.ts +4 -1
- package/dist/lib/api/invitation.d.ts.map +1 -1
- package/dist/lib/api/model.d.ts +180 -11
- package/dist/lib/api/model.d.ts.map +1 -1
- package/dist/lib/api/setting.d.ts +4 -1
- package/dist/lib/api/setting.d.ts.map +1 -1
- package/dist/lib/api/tenant.d.ts +4 -1
- package/dist/lib/api/tenant.d.ts.map +1 -1
- package/dist/lib/api/two-factor.d.ts +75 -0
- package/dist/lib/api/two-factor.d.ts.map +1 -0
- package/dist/lib/api/user.d.ts +4 -1
- package/dist/lib/api/user.d.ts.map +1 -1
- package/dist/lib/constants/index.d.ts +25 -0
- package/dist/lib/constants/index.d.ts.map +1 -1
- package/dist/lib/device/index.d.ts +17 -0
- package/dist/lib/device/index.d.ts.map +1 -0
- package/dist/lib/index.d.ts +10 -3
- package/dist/lib/index.d.ts.map +1 -1
- package/dist/lib/m2m/client.d.ts +196 -0
- package/dist/lib/m2m/client.d.ts.map +1 -0
- package/dist/lib/m2m/errors.d.ts +107 -0
- package/dist/lib/m2m/errors.d.ts.map +1 -0
- package/dist/lib/m2m/index.d.ts +27 -0
- package/dist/lib/m2m/index.d.ts.map +1 -0
- package/dist/lib/m2m/types.d.ts +217 -0
- package/dist/lib/m2m/types.d.ts.map +1 -0
- package/dist/lib/passflow.d.ts +972 -11
- package/dist/lib/passflow.d.ts.map +1 -1
- package/dist/lib/services/auth-service.d.ts +29 -4
- package/dist/lib/services/auth-service.d.ts.map +1 -1
- package/dist/lib/services/index.d.ts +2 -1
- package/dist/lib/services/index.d.ts.map +1 -1
- package/dist/lib/services/invitation-service.d.ts +2 -2
- package/dist/lib/services/tenant-service.d.ts +2 -2
- package/dist/lib/services/token-cache-service.d.ts +14 -6
- package/dist/lib/services/token-cache-service.d.ts.map +1 -1
- package/dist/lib/services/two-factor-service.d.ts +120 -0
- package/dist/lib/services/two-factor-service.d.ts.map +1 -0
- package/dist/lib/services/user-service.d.ts +1 -1
- package/dist/lib/services/user-service.d.ts.map +1 -1
- package/dist/lib/storage/index.d.ts +96 -0
- package/dist/lib/storage/index.d.ts.map +1 -0
- package/dist/lib/store.d.ts +67 -1
- package/dist/lib/store.d.ts.map +1 -1
- package/dist/lib/token/delivery-manager.d.ts +121 -0
- package/dist/lib/token/delivery-manager.d.ts.map +1 -0
- package/dist/lib/{token-service → token}/index.d.ts +1 -1
- package/dist/lib/token/index.d.ts.map +1 -0
- package/dist/lib/token/membership.d.ts.map +1 -0
- package/dist/lib/{token-service → token}/service.d.ts +15 -3
- package/dist/lib/token/service.d.ts.map +1 -0
- package/dist/lib/token/token.d.ts +55 -0
- package/dist/lib/token/token.d.ts.map +1 -0
- package/dist/lib/types/index.d.ts +5 -3
- package/dist/lib/types/index.d.ts.map +1 -1
- package/dist/lib/utils/validation.d.ts +54 -0
- package/dist/lib/utils/validation.d.ts.map +1 -0
- package/dist/tests/storage/fake-storage.d.ts.map +1 -0
- package/dist/tests/storage/storage-manager.test.d.ts.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +14 -15
- package/dist/lib/device-service/index.d.ts +0 -7
- package/dist/lib/device-service/index.d.ts.map +0 -1
- package/dist/lib/storage-manager/index.d.ts +0 -37
- package/dist/lib/storage-manager/index.d.ts.map +0 -1
- package/dist/lib/token-service/index.d.ts.map +0 -1
- package/dist/lib/token-service/membership.d.ts.map +0 -1
- package/dist/lib/token-service/service.d.ts.map +0 -1
- package/dist/lib/token-service/token.d.ts +0 -34
- package/dist/lib/token-service/token.d.ts.map +0 -1
- package/dist/tests/storage-manager/fake-storage.d.ts.map +0 -1
- package/dist/tests/storage-manager/storage-manager.test.d.ts.map +0 -1
- /package/dist/lib/{token-service → token}/membership.d.ts +0 -0
- /package/dist/tests/{storage-manager → storage}/fake-storage.d.ts +0 -0
- /package/dist/tests/{storage-manager → storage}/storage-manager.test.d.ts +0 -0
package/dist/lib/passflow.d.ts
CHANGED
|
@@ -1,15 +1,25 @@
|
|
|
1
|
-
import { type AppSettings, type InvitationsPaginatedList, type InviteLinkResponse, type PassflowAuthorizationResponse, type PassflowConfig, PassflowFederatedAuthPayload, type PassflowPasskeyAuthenticateStartPayload, type PassflowPasskeyRegisterStartPayload, type PassflowPasskeySettings, type PassflowPasswordPolicySettings, type PassflowPasswordlessResponse, type PassflowPasswordlessSignInCompletePayload, type PassflowPasswordlessSignInPayload, type PassflowSendPasswordResetEmailPayload, type PassflowSettingsAll, type PassflowSignInPayload, type PassflowSignUpPayload, type PassflowSuccessResponse, type PassflowTenantResponse, type PassflowValidationResponse, type RequestInviteLinkPayload } from './api';
|
|
2
|
-
import { TenantService } from './services';
|
|
1
|
+
import { type AppSettings, type InvitationsPaginatedList, type InviteLinkResponse, type PassflowAuthorizationResponse, type PassflowConfig, PassflowFederatedAuthPayload, type PassflowPasskeyAuthenticateStartPayload, type PassflowPasskeyRegisterStartPayload, type PassflowPasskeySettings, type PassflowPasswordPolicySettings, type PassflowPasswordlessResponse, type PassflowPasswordlessSignInCompletePayload, type PassflowPasswordlessSignInPayload, type PassflowSendPasswordResetEmailPayload, type PassflowSettingsAll, type PassflowSignInPayload, type PassflowSignUpPayload, type PassflowSuccessResponse, type PassflowTenantResponse, type PassflowValidationResponse, type RequestInviteLinkPayload, type TwoFactorConfirmResponse, type TwoFactorDisableResponse, type TwoFactorRecoveryResponse, type TwoFactorRegenerateResponse, type TwoFactorSetupResponse, type TwoFactorStatusResponse, type TwoFactorVerifyResponse } from './api';
|
|
2
|
+
import { TenantService, TwoFactorService } from './services';
|
|
3
3
|
import { PassflowEvent, type PassflowSubscriber } from './store';
|
|
4
|
-
import { type TokenType } from './token
|
|
4
|
+
import { type TokenType } from './token';
|
|
5
5
|
import type { ParsedTokens, SessionParams, Tokens } from './types';
|
|
6
6
|
export declare class Passflow {
|
|
7
|
+
/**
|
|
8
|
+
* SDK version string.
|
|
9
|
+
* Useful for debugging and reporting version-specific issues.
|
|
10
|
+
* @example
|
|
11
|
+
* ```typescript
|
|
12
|
+
* console.log('Using Passflow SDK version:', Passflow.version);
|
|
13
|
+
* ```
|
|
14
|
+
*/
|
|
15
|
+
static readonly version: string;
|
|
7
16
|
private authApi;
|
|
8
17
|
private appApi;
|
|
9
18
|
private userApi;
|
|
10
19
|
private settingApi;
|
|
11
|
-
private
|
|
12
|
-
private
|
|
20
|
+
private tenantApi;
|
|
21
|
+
private invitationApi;
|
|
22
|
+
private twoFactorApi;
|
|
13
23
|
private scopes;
|
|
14
24
|
private createTenantForNewUser;
|
|
15
25
|
private doRefreshTokens;
|
|
@@ -21,7 +31,9 @@ export declare class Passflow {
|
|
|
21
31
|
private tenantService;
|
|
22
32
|
private invitationService;
|
|
23
33
|
private tokenCacheService;
|
|
34
|
+
private twoFactorService;
|
|
24
35
|
tenant: TenantService;
|
|
36
|
+
twoFactor: TwoFactorService;
|
|
25
37
|
private createSessionCallback?;
|
|
26
38
|
private expiredSessionCallback?;
|
|
27
39
|
error?: Error;
|
|
@@ -29,42 +41,646 @@ export declare class Passflow {
|
|
|
29
41
|
url: string;
|
|
30
42
|
appId?: string;
|
|
31
43
|
constructor(config: PassflowConfig);
|
|
44
|
+
/**
|
|
45
|
+
* Update the appId and propagate it to all API clients.
|
|
46
|
+
* This ensures that all future API requests use the new appId in their headers.
|
|
47
|
+
*
|
|
48
|
+
* @param appId - The new application ID to set
|
|
49
|
+
*
|
|
50
|
+
* @example
|
|
51
|
+
* ```typescript
|
|
52
|
+
* // Update appId after discovery
|
|
53
|
+
* passflow.setAppId('discovered-app-id-123');
|
|
54
|
+
* ```
|
|
55
|
+
*/
|
|
56
|
+
setAppId(appId: string): void;
|
|
57
|
+
/**
|
|
58
|
+
* Configure session callbacks and check current session status.
|
|
59
|
+
*
|
|
60
|
+
* **WARNING**: Calling this method multiple times will overwrite previously registered callbacks.
|
|
61
|
+
* Only the most recent `createSession` and `expiredSession` callbacks will be active.
|
|
62
|
+
*
|
|
63
|
+
* @param params - Session configuration parameters
|
|
64
|
+
* @param params.createSession - Callback invoked when a valid session exists or is created
|
|
65
|
+
* @param params.expiredSession - Callback invoked when no valid session exists
|
|
66
|
+
* @param params.doRefresh - Whether to automatically refresh expired tokens (default: false)
|
|
67
|
+
* @returns Promise that resolves when session check is complete
|
|
68
|
+
*
|
|
69
|
+
* @example
|
|
70
|
+
* ```typescript
|
|
71
|
+
* await passflow.session({
|
|
72
|
+
* createSession: async ({ tokens, parsedTokens }) => {
|
|
73
|
+
* console.log('User is authenticated', parsedTokens?.access_token?.sub);
|
|
74
|
+
* // Initialize user session in your app
|
|
75
|
+
* },
|
|
76
|
+
* expiredSession: async () => {
|
|
77
|
+
* console.log('User session expired');
|
|
78
|
+
* // Redirect to login or show login modal
|
|
79
|
+
* },
|
|
80
|
+
* doRefresh: true // Automatically refresh tokens if expired
|
|
81
|
+
* });
|
|
82
|
+
* ```
|
|
83
|
+
*/
|
|
32
84
|
session: ({ createSession, expiredSession, doRefresh }: SessionParams) => Promise<void>;
|
|
33
85
|
private submitSessionCheck;
|
|
34
|
-
|
|
35
|
-
|
|
86
|
+
/**
|
|
87
|
+
* Subscribe to Passflow authentication events.
|
|
88
|
+
*
|
|
89
|
+
* @param subscriber - Subscriber function that receives event type and payload
|
|
90
|
+
* @param events - Optional array of specific events to listen for. If omitted, subscribes to all events.
|
|
91
|
+
*
|
|
92
|
+
* @example
|
|
93
|
+
* ```typescript
|
|
94
|
+
* // Subscribe to all events
|
|
95
|
+
* passflow.subscribe((event, payload) => {
|
|
96
|
+
* console.log('Event:', event, payload);
|
|
97
|
+
* });
|
|
98
|
+
*
|
|
99
|
+
* // Subscribe to specific events only
|
|
100
|
+
* passflow.subscribe(
|
|
101
|
+
* (event, payload) => {
|
|
102
|
+
* if (event === PassflowEvent.SignIn) {
|
|
103
|
+
* console.log('User signed in', payload.tokens);
|
|
104
|
+
* }
|
|
105
|
+
* },
|
|
106
|
+
* [PassflowEvent.SignIn, PassflowEvent.SignOut]
|
|
107
|
+
* );
|
|
108
|
+
* ```
|
|
109
|
+
*/
|
|
110
|
+
subscribe(subscriber: PassflowSubscriber, events?: PassflowEvent[]): void;
|
|
111
|
+
/**
|
|
112
|
+
* Unsubscribe from Passflow authentication events.
|
|
113
|
+
*
|
|
114
|
+
* @param subscriber - The subscriber function to remove
|
|
115
|
+
* @param events - Optional array of specific events to unsubscribe from. If omitted, unsubscribes from all events.
|
|
116
|
+
*
|
|
117
|
+
* @example
|
|
118
|
+
* ```typescript
|
|
119
|
+
* const subscriber = (event, payload) => console.log(event, payload);
|
|
120
|
+
*
|
|
121
|
+
* // Subscribe
|
|
122
|
+
* passflow.subscribe(subscriber);
|
|
123
|
+
*
|
|
124
|
+
* // Later, unsubscribe
|
|
125
|
+
* passflow.unsubscribe(subscriber);
|
|
126
|
+
* ```
|
|
127
|
+
*/
|
|
128
|
+
unsubscribe(subscriber: PassflowSubscriber, events?: PassflowEvent[]): void;
|
|
129
|
+
/**
|
|
130
|
+
* Handle OAuth redirect callback and extract tokens from URL query parameters.
|
|
131
|
+
* This method should be called on the redirect page after authentication.
|
|
132
|
+
*
|
|
133
|
+
* @returns Tokens object if found in URL, undefined otherwise
|
|
134
|
+
*
|
|
135
|
+
* @example
|
|
136
|
+
* ```typescript
|
|
137
|
+
* // On your redirect page (e.g., /auth/callback)
|
|
138
|
+
* const tokens = passflow.handleTokensRedirect();
|
|
139
|
+
* if (tokens) {
|
|
140
|
+
* console.log('Authentication successful', tokens.access_token);
|
|
141
|
+
* // Tokens are automatically saved to storage
|
|
142
|
+
* }
|
|
143
|
+
* ```
|
|
144
|
+
*/
|
|
36
145
|
handleTokensRedirect(): Tokens | undefined;
|
|
37
146
|
private checkAndSetTokens;
|
|
38
147
|
private checkErrorsFromURL;
|
|
148
|
+
private cleanupUrlParams;
|
|
39
149
|
private setTokensToCacheFromLocalStorage;
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
150
|
+
/**
|
|
151
|
+
* Get cached tokens from memory without triggering a refresh.
|
|
152
|
+
*
|
|
153
|
+
* @returns Cached tokens or undefined if not cached
|
|
154
|
+
*
|
|
155
|
+
* @example
|
|
156
|
+
* ```typescript
|
|
157
|
+
* const tokens = passflow.getCachedTokens();
|
|
158
|
+
* if (tokens) {
|
|
159
|
+
* console.log('Access token:', tokens.access_token);
|
|
160
|
+
* }
|
|
161
|
+
* ```
|
|
162
|
+
*/
|
|
163
|
+
getCachedTokens(): Tokens | undefined;
|
|
164
|
+
/**
|
|
165
|
+
* Get cached tokens from memory and automatically refresh if expired.
|
|
166
|
+
*
|
|
167
|
+
* @returns Promise resolving to tokens or undefined
|
|
168
|
+
*
|
|
169
|
+
* @example
|
|
170
|
+
* ```typescript
|
|
171
|
+
* const tokens = await passflow.getTokensWithRefresh();
|
|
172
|
+
* // Tokens are guaranteed to be valid or undefined
|
|
173
|
+
* ```
|
|
174
|
+
*/
|
|
175
|
+
getTokensWithRefresh(): Promise<Tokens | undefined>;
|
|
176
|
+
/**
|
|
177
|
+
* Get parsed JWT tokens with decoded claims.
|
|
178
|
+
*
|
|
179
|
+
* @returns Parsed token objects with decoded payloads
|
|
180
|
+
*
|
|
181
|
+
* @example
|
|
182
|
+
* ```typescript
|
|
183
|
+
* const parsed = passflow.getParsedTokens();
|
|
184
|
+
* if (parsed?.access_token) {
|
|
185
|
+
* console.log('User ID:', parsed.access_token.sub);
|
|
186
|
+
* console.log('Expires at:', new Date(parsed.access_token.exp * 1000));
|
|
187
|
+
* }
|
|
188
|
+
* ```
|
|
189
|
+
*/
|
|
190
|
+
getParsedTokens(): ParsedTokens | undefined;
|
|
191
|
+
/**
|
|
192
|
+
* Check if the cached tokens are expired.
|
|
193
|
+
*
|
|
194
|
+
* @returns True if tokens are expired, false otherwise
|
|
195
|
+
*
|
|
196
|
+
* @example
|
|
197
|
+
* ```typescript
|
|
198
|
+
* if (passflow.areTokensExpired()) {
|
|
199
|
+
* await passflow.refreshToken();
|
|
200
|
+
* }
|
|
201
|
+
* ```
|
|
202
|
+
*/
|
|
203
|
+
areTokensExpired(): boolean;
|
|
204
|
+
/**
|
|
205
|
+
* Check if the user is currently authenticated with valid tokens.
|
|
206
|
+
*
|
|
207
|
+
* @returns True if user has valid, non-expired tokens
|
|
208
|
+
*
|
|
209
|
+
* @example
|
|
210
|
+
* ```typescript
|
|
211
|
+
* if (passflow.isAuthenticated()) {
|
|
212
|
+
* console.log('User is logged in');
|
|
213
|
+
* } else {
|
|
214
|
+
* console.log('User needs to sign in');
|
|
215
|
+
* }
|
|
216
|
+
* ```
|
|
217
|
+
*/
|
|
44
218
|
isAuthenticated(): boolean;
|
|
219
|
+
/**
|
|
220
|
+
* Sign in a user with email/username and password.
|
|
221
|
+
*
|
|
222
|
+
* @param payload - Sign-in credentials and options
|
|
223
|
+
* @param payload.email - User's email or username
|
|
224
|
+
* @param payload.password - User's password
|
|
225
|
+
* @param payload.scopes - Optional scopes to request (defaults to SDK scopes)
|
|
226
|
+
* @returns Promise with authorization response containing tokens
|
|
227
|
+
* @throws {PassflowError} If authentication fails
|
|
228
|
+
*
|
|
229
|
+
* @example
|
|
230
|
+
* ```typescript
|
|
231
|
+
* try {
|
|
232
|
+
* const response = await passflow.signIn({
|
|
233
|
+
* email: 'user@example.com',
|
|
234
|
+
* password: 'secure-password'
|
|
235
|
+
* });
|
|
236
|
+
* console.log('Signed in successfully', response.access_token);
|
|
237
|
+
* } catch (error) {
|
|
238
|
+
* console.error('Sign in failed', error.message);
|
|
239
|
+
* }
|
|
240
|
+
* ```
|
|
241
|
+
*/
|
|
45
242
|
signIn(payload: PassflowSignInPayload): Promise<PassflowAuthorizationResponse>;
|
|
243
|
+
/**
|
|
244
|
+
* Register a new user account with email and password.
|
|
245
|
+
*
|
|
246
|
+
* @param payload - Registration details
|
|
247
|
+
* @param payload.email - User's email address
|
|
248
|
+
* @param payload.password - User's password
|
|
249
|
+
* @param payload.username - Optional username
|
|
250
|
+
* @param payload.scopes - Optional scopes to request
|
|
251
|
+
* @returns Promise with authorization response containing tokens
|
|
252
|
+
* @throws {PassflowError} If registration fails
|
|
253
|
+
*
|
|
254
|
+
* @example
|
|
255
|
+
* ```typescript
|
|
256
|
+
* try {
|
|
257
|
+
* const response = await passflow.signUp({
|
|
258
|
+
* email: 'newuser@example.com',
|
|
259
|
+
* password: 'secure-password',
|
|
260
|
+
* username: 'newuser'
|
|
261
|
+
* });
|
|
262
|
+
* console.log('Account created', response.access_token);
|
|
263
|
+
* } catch (error) {
|
|
264
|
+
* console.error('Sign up failed', error.message);
|
|
265
|
+
* }
|
|
266
|
+
* ```
|
|
267
|
+
*/
|
|
46
268
|
signUp(payload: PassflowSignUpPayload): Promise<PassflowAuthorizationResponse>;
|
|
269
|
+
/**
|
|
270
|
+
* Initiate passwordless authentication by sending a magic link or OTP.
|
|
271
|
+
*
|
|
272
|
+
* @param payload - Passwordless sign-in configuration
|
|
273
|
+
* @param payload.email - User's email address
|
|
274
|
+
* @param payload.method - Delivery method ('email' or 'sms')
|
|
275
|
+
* @returns Promise with response indicating if the code was sent
|
|
276
|
+
* @throws {PassflowError} If request fails
|
|
277
|
+
*
|
|
278
|
+
* @example
|
|
279
|
+
* ```typescript
|
|
280
|
+
* // Send magic link via email
|
|
281
|
+
* const response = await passflow.passwordlessSignIn({
|
|
282
|
+
* email: 'user@example.com',
|
|
283
|
+
* method: 'email'
|
|
284
|
+
* });
|
|
285
|
+
* console.log('Magic link sent:', response.success);
|
|
286
|
+
* ```
|
|
287
|
+
*/
|
|
47
288
|
passwordlessSignIn(payload: PassflowPasswordlessSignInPayload): Promise<PassflowPasswordlessResponse>;
|
|
289
|
+
/**
|
|
290
|
+
* Complete passwordless authentication by verifying the OTP or token.
|
|
291
|
+
*
|
|
292
|
+
* @param payload - Verification payload
|
|
293
|
+
* @param payload.email - User's email address
|
|
294
|
+
* @param payload.code - Verification code from email/SMS
|
|
295
|
+
* @param payload.scopes - Optional scopes to request
|
|
296
|
+
* @returns Promise with validation response containing tokens
|
|
297
|
+
* @throws {PassflowError} If verification fails
|
|
298
|
+
*
|
|
299
|
+
* @example
|
|
300
|
+
* ```typescript
|
|
301
|
+
* try {
|
|
302
|
+
* const response = await passflow.passwordlessSignInComplete({
|
|
303
|
+
* email: 'user@example.com',
|
|
304
|
+
* code: '123456'
|
|
305
|
+
* });
|
|
306
|
+
* console.log('Passwordless sign-in complete', response.access_token);
|
|
307
|
+
* } catch (error) {
|
|
308
|
+
* console.error('Invalid code', error.message);
|
|
309
|
+
* }
|
|
310
|
+
* ```
|
|
311
|
+
*/
|
|
48
312
|
passwordlessSignInComplete(payload: PassflowPasswordlessSignInCompletePayload): Promise<PassflowValidationResponse>;
|
|
313
|
+
/**
|
|
314
|
+
* Centralized error handler for all public methods.
|
|
315
|
+
* Creates proper ErrorPayload, distinguishes PassflowError from generic Error,
|
|
316
|
+
* notifies error event, and re-throws the error.
|
|
317
|
+
*
|
|
318
|
+
* @param error - The error to handle
|
|
319
|
+
* @param context - Context description for the error
|
|
320
|
+
* @throws The original error after handling
|
|
321
|
+
*/
|
|
322
|
+
private handleError;
|
|
323
|
+
/**
|
|
324
|
+
* Sign out the current user and clear all tokens.
|
|
325
|
+
*
|
|
326
|
+
* @returns Promise that resolves when sign-out is complete
|
|
327
|
+
* @throws {PassflowError} If sign-out request fails
|
|
328
|
+
*
|
|
329
|
+
* @example
|
|
330
|
+
* ```typescript
|
|
331
|
+
* try {
|
|
332
|
+
* await passflow.logOut();
|
|
333
|
+
* console.log('User signed out successfully');
|
|
334
|
+
* // Redirect to login page
|
|
335
|
+
* } catch (error) {
|
|
336
|
+
* console.error('Sign out failed', error.message);
|
|
337
|
+
* }
|
|
338
|
+
* ```
|
|
339
|
+
*/
|
|
49
340
|
logOut(): Promise<void>;
|
|
341
|
+
/**
|
|
342
|
+
* Initiate federated authentication (OAuth) with a popup window.
|
|
343
|
+
*
|
|
344
|
+
* @param payload - Federated authentication configuration
|
|
345
|
+
* @param payload.provider - OAuth provider (e.g., 'google', 'github', 'microsoft')
|
|
346
|
+
* @param payload.scopes - Optional scopes to request
|
|
347
|
+
*
|
|
348
|
+
* @example
|
|
349
|
+
* ```typescript
|
|
350
|
+
* // Sign in with Google using a popup
|
|
351
|
+
* passflow.federatedAuthWithPopup({
|
|
352
|
+
* provider: 'google'
|
|
353
|
+
* });
|
|
354
|
+
*
|
|
355
|
+
* // Listen for the result via subscribe
|
|
356
|
+
* passflow.subscribe((event, payload) => {
|
|
357
|
+
* if (event === PassflowEvent.SignIn) {
|
|
358
|
+
* console.log('OAuth sign-in successful', payload.tokens);
|
|
359
|
+
* }
|
|
360
|
+
* });
|
|
361
|
+
* ```
|
|
362
|
+
*/
|
|
50
363
|
federatedAuthWithPopup(payload: PassflowFederatedAuthPayload): void;
|
|
364
|
+
/**
|
|
365
|
+
* Initiate federated authentication (OAuth) with a full-page redirect.
|
|
366
|
+
*
|
|
367
|
+
* @param payload - Federated authentication configuration
|
|
368
|
+
* @param payload.provider - OAuth provider (e.g., 'google', 'github', 'microsoft')
|
|
369
|
+
* @param payload.scopes - Optional scopes to request
|
|
370
|
+
* @param payload.redirectUrl - URL to redirect to after authentication
|
|
371
|
+
*
|
|
372
|
+
* @example
|
|
373
|
+
* ```typescript
|
|
374
|
+
* // Sign in with GitHub using redirect
|
|
375
|
+
* passflow.federatedAuthWithRedirect({
|
|
376
|
+
* provider: 'github',
|
|
377
|
+
* redirectUrl: window.location.origin + '/auth/callback'
|
|
378
|
+
* });
|
|
379
|
+
* ```
|
|
380
|
+
*/
|
|
51
381
|
federatedAuthWithRedirect(payload: PassflowFederatedAuthPayload): void;
|
|
382
|
+
/**
|
|
383
|
+
* Reset the SDK state by clearing all tokens and optionally throwing an error.
|
|
384
|
+
*
|
|
385
|
+
* @param error - Optional error message to throw after reset
|
|
386
|
+
* @throws {Error} If error message is provided
|
|
387
|
+
*
|
|
388
|
+
* @example
|
|
389
|
+
* ```typescript
|
|
390
|
+
* // Clear tokens without error
|
|
391
|
+
* passflow.reset();
|
|
392
|
+
*
|
|
393
|
+
* // Clear tokens and throw error
|
|
394
|
+
* try {
|
|
395
|
+
* passflow.reset('Session expired');
|
|
396
|
+
* } catch (error) {
|
|
397
|
+
* console.error('Reset error:', error.message);
|
|
398
|
+
* }
|
|
399
|
+
* ```
|
|
400
|
+
*/
|
|
52
401
|
reset(error?: string): void;
|
|
402
|
+
/**
|
|
403
|
+
* Refresh the access token using the refresh token.
|
|
404
|
+
*
|
|
405
|
+
* @returns Promise with new authorization response containing refreshed tokens
|
|
406
|
+
* @throws {Error} If no refresh token is found
|
|
407
|
+
* @throws {PassflowError} If refresh request fails
|
|
408
|
+
*
|
|
409
|
+
* @example
|
|
410
|
+
* ```typescript
|
|
411
|
+
* try {
|
|
412
|
+
* const response = await passflow.refreshToken();
|
|
413
|
+
* console.log('Token refreshed', response.access_token);
|
|
414
|
+
* } catch (error) {
|
|
415
|
+
* console.error('Failed to refresh token', error.message);
|
|
416
|
+
* // Redirect to login
|
|
417
|
+
* }
|
|
418
|
+
* ```
|
|
419
|
+
*/
|
|
53
420
|
refreshToken(): Promise<PassflowAuthorizationResponse>;
|
|
421
|
+
/**
|
|
422
|
+
* Send a password reset email to the user.
|
|
423
|
+
*
|
|
424
|
+
* @param payload - Password reset request
|
|
425
|
+
* @param payload.email - User's email address
|
|
426
|
+
* @returns Promise with success response
|
|
427
|
+
* @throws {PassflowError} If request fails
|
|
428
|
+
*
|
|
429
|
+
* @example
|
|
430
|
+
* ```typescript
|
|
431
|
+
* try {
|
|
432
|
+
* await passflow.sendPasswordResetEmail({
|
|
433
|
+
* email: 'user@example.com'
|
|
434
|
+
* });
|
|
435
|
+
* console.log('Password reset email sent');
|
|
436
|
+
* } catch (error) {
|
|
437
|
+
* console.error('Failed to send reset email', error.message);
|
|
438
|
+
* }
|
|
439
|
+
* ```
|
|
440
|
+
*/
|
|
54
441
|
sendPasswordResetEmail(payload: PassflowSendPasswordResetEmailPayload): Promise<PassflowSuccessResponse>;
|
|
442
|
+
/**
|
|
443
|
+
* Reset password using a reset token (typically from URL after clicking email link).
|
|
444
|
+
*
|
|
445
|
+
* @param newPassword - The new password to set
|
|
446
|
+
* @param scopes - Optional scopes to request after reset
|
|
447
|
+
* @returns Promise with authorization response containing new tokens
|
|
448
|
+
* @throws {PassflowError} If reset fails
|
|
449
|
+
*
|
|
450
|
+
* @example
|
|
451
|
+
* ```typescript
|
|
452
|
+
* // On password reset page (e.g., /reset-password?token=xyz)
|
|
453
|
+
* try {
|
|
454
|
+
* const response = await passflow.resetPassword('new-secure-password');
|
|
455
|
+
* console.log('Password reset successful', response.access_token);
|
|
456
|
+
* } catch (error) {
|
|
457
|
+
* console.error('Password reset failed', error.message);
|
|
458
|
+
* }
|
|
459
|
+
* ```
|
|
460
|
+
*/
|
|
55
461
|
resetPassword(newPassword: string, scopes?: string[]): Promise<PassflowAuthorizationResponse>;
|
|
462
|
+
/**
|
|
463
|
+
* Get application settings and configuration.
|
|
464
|
+
*
|
|
465
|
+
* @returns Promise with app settings including branding, features, and config
|
|
466
|
+
* @throws {PassflowError} If request fails
|
|
467
|
+
*
|
|
468
|
+
* @example
|
|
469
|
+
* ```typescript
|
|
470
|
+
* const settings = await passflow.getAppSettings();
|
|
471
|
+
* console.log('App name:', settings.name);
|
|
472
|
+
* console.log('Passwordless enabled:', settings.passwordless_enabled);
|
|
473
|
+
* ```
|
|
474
|
+
*/
|
|
56
475
|
getAppSettings(): Promise<AppSettings>;
|
|
476
|
+
/**
|
|
477
|
+
* Get all Passflow settings including password policy, passkey settings, etc.
|
|
478
|
+
*
|
|
479
|
+
* @returns Promise with all settings
|
|
480
|
+
* @throws {PassflowError} If request fails
|
|
481
|
+
*
|
|
482
|
+
* @example
|
|
483
|
+
* ```typescript
|
|
484
|
+
* const settings = await passflow.getSettingsAll();
|
|
485
|
+
* console.log('Password policy:', settings.password_policy);
|
|
486
|
+
* console.log('Passkey settings:', settings.passkey);
|
|
487
|
+
* ```
|
|
488
|
+
*/
|
|
57
489
|
getSettingsAll(): Promise<PassflowSettingsAll>;
|
|
490
|
+
/**
|
|
491
|
+
* Get password policy settings (min length, complexity requirements, etc.).
|
|
492
|
+
*
|
|
493
|
+
* @returns Promise with password policy configuration
|
|
494
|
+
* @throws {PassflowError} If request fails
|
|
495
|
+
*
|
|
496
|
+
* @example
|
|
497
|
+
* ```typescript
|
|
498
|
+
* const policy = await passflow.getPasswordPolicySettings();
|
|
499
|
+
* console.log('Min length:', policy.min_length);
|
|
500
|
+
* console.log('Require uppercase:', policy.require_uppercase);
|
|
501
|
+
* ```
|
|
502
|
+
*/
|
|
58
503
|
getPasswordPolicySettings(): Promise<PassflowPasswordPolicySettings>;
|
|
504
|
+
/**
|
|
505
|
+
* Get passkey (WebAuthn) configuration settings.
|
|
506
|
+
*
|
|
507
|
+
* @returns Promise with passkey settings
|
|
508
|
+
* @throws {PassflowError} If request fails
|
|
509
|
+
*
|
|
510
|
+
* @example
|
|
511
|
+
* ```typescript
|
|
512
|
+
* const passkeySettings = await passflow.getPasskeySettings();
|
|
513
|
+
* console.log('Passkeys enabled:', passkeySettings.enabled);
|
|
514
|
+
* console.log('User verification:', passkeySettings.user_verification);
|
|
515
|
+
* ```
|
|
516
|
+
*/
|
|
59
517
|
getPasskeySettings(): Promise<PassflowPasskeySettings>;
|
|
518
|
+
/**
|
|
519
|
+
* Register a new user with a passkey (WebAuthn).
|
|
520
|
+
*
|
|
521
|
+
* @param payload - Passkey registration configuration
|
|
522
|
+
* @param payload.email - User's email address
|
|
523
|
+
* @param payload.username - Optional username
|
|
524
|
+
* @param payload.scopes - Optional scopes to request
|
|
525
|
+
* @returns Promise with authorization response containing tokens
|
|
526
|
+
* @throws {PassflowError} If passkey registration fails
|
|
527
|
+
*
|
|
528
|
+
* @example
|
|
529
|
+
* ```typescript
|
|
530
|
+
* try {
|
|
531
|
+
* const response = await passflow.passkeyRegister({
|
|
532
|
+
* email: 'user@example.com',
|
|
533
|
+
* username: 'myusername'
|
|
534
|
+
* });
|
|
535
|
+
* console.log('Passkey registered', response.access_token);
|
|
536
|
+
* } catch (error) {
|
|
537
|
+
* console.error('Passkey registration failed', error.message);
|
|
538
|
+
* }
|
|
539
|
+
* ```
|
|
540
|
+
*/
|
|
60
541
|
passkeyRegister(payload: PassflowPasskeyRegisterStartPayload): Promise<PassflowAuthorizationResponse>;
|
|
542
|
+
/**
|
|
543
|
+
* Authenticate a user with a passkey (WebAuthn).
|
|
544
|
+
*
|
|
545
|
+
* @param payload - Passkey authentication configuration
|
|
546
|
+
* @param payload.email - Optional user email to pre-fill
|
|
547
|
+
* @param payload.scopes - Optional scopes to request
|
|
548
|
+
* @returns Promise with authorization response containing tokens
|
|
549
|
+
* @throws {PassflowError} If passkey authentication fails
|
|
550
|
+
*
|
|
551
|
+
* @example
|
|
552
|
+
* ```typescript
|
|
553
|
+
* try {
|
|
554
|
+
* // Let user select from available passkeys
|
|
555
|
+
* const response = await passflow.passkeyAuthenticate({});
|
|
556
|
+
* console.log('Passkey sign-in successful', response.access_token);
|
|
557
|
+
* } catch (error) {
|
|
558
|
+
* console.error('Passkey authentication failed', error.message);
|
|
559
|
+
* }
|
|
560
|
+
* ```
|
|
561
|
+
*/
|
|
61
562
|
passkeyAuthenticate(payload: PassflowPasskeyAuthenticateStartPayload): Promise<PassflowAuthorizationResponse>;
|
|
563
|
+
/**
|
|
564
|
+
* Manually set tokens (useful after custom authentication flows).
|
|
565
|
+
* This will save tokens to storage, update cache, and trigger SignIn event.
|
|
566
|
+
*
|
|
567
|
+
* @param tokensData - Tokens object to set
|
|
568
|
+
* @param tokensData.access_token - JWT access token
|
|
569
|
+
* @param tokensData.refresh_token - Optional refresh token
|
|
570
|
+
* @param tokensData.id_token - Optional ID token
|
|
571
|
+
* @param tokensData.scopes - Token scopes
|
|
572
|
+
*
|
|
573
|
+
* @example
|
|
574
|
+
* ```typescript
|
|
575
|
+
* // Set tokens from a custom auth flow
|
|
576
|
+
* passflow.setTokens({
|
|
577
|
+
* access_token: 'eyJhbGci...',
|
|
578
|
+
* refresh_token: 'eyJhbGci...',
|
|
579
|
+
* id_token: 'eyJhbGci...',
|
|
580
|
+
* scopes: ['id', 'offline', 'email']
|
|
581
|
+
* });
|
|
582
|
+
* ```
|
|
583
|
+
*/
|
|
62
584
|
setTokens(tokensData: Tokens): void;
|
|
585
|
+
/**
|
|
586
|
+
* Get current tokens from storage, optionally refreshing if expired.
|
|
587
|
+
*
|
|
588
|
+
* @param doRefresh - If true, automatically refresh expired tokens (default: false)
|
|
589
|
+
* @returns Promise with tokens or undefined if not authenticated
|
|
590
|
+
*
|
|
591
|
+
* @example
|
|
592
|
+
* ```typescript
|
|
593
|
+
* // Get tokens without refresh
|
|
594
|
+
* const tokens = await passflow.getTokens();
|
|
595
|
+
*
|
|
596
|
+
* // Get tokens and auto-refresh if expired
|
|
597
|
+
* const freshTokens = await passflow.getTokens(true);
|
|
598
|
+
* ```
|
|
599
|
+
*/
|
|
63
600
|
getTokens(doRefresh?: boolean): Promise<Tokens | undefined>;
|
|
601
|
+
/**
|
|
602
|
+
* Get a specific token from storage by type.
|
|
603
|
+
*
|
|
604
|
+
* @param tokenType - Type of token to retrieve ('access_token', 'refresh_token', 'id_token')
|
|
605
|
+
* @returns Token string or undefined if not found
|
|
606
|
+
*
|
|
607
|
+
* @example
|
|
608
|
+
* ```typescript
|
|
609
|
+
* const accessToken = passflow.getToken('access_token');
|
|
610
|
+
* if (accessToken) {
|
|
611
|
+
* // Use token for API calls
|
|
612
|
+
* fetch('/api/data', {
|
|
613
|
+
* headers: { Authorization: `Bearer ${accessToken}` }
|
|
614
|
+
* });
|
|
615
|
+
* }
|
|
616
|
+
* ```
|
|
617
|
+
*/
|
|
64
618
|
getToken(tokenType: TokenType): string | undefined;
|
|
619
|
+
/**
|
|
620
|
+
* Get list of passkeys registered for the current user.
|
|
621
|
+
*
|
|
622
|
+
* @returns Promise with array of user's passkeys
|
|
623
|
+
* @throws {PassflowError} If request fails
|
|
624
|
+
*
|
|
625
|
+
* @example
|
|
626
|
+
* ```typescript
|
|
627
|
+
* const passkeys = await passflow.getUserPasskeys();
|
|
628
|
+
* passkeys.forEach(passkey => {
|
|
629
|
+
* console.log('Passkey:', passkey.name, passkey.id);
|
|
630
|
+
* });
|
|
631
|
+
* ```
|
|
632
|
+
*/
|
|
65
633
|
getUserPasskeys(): Promise<import("./api").PassflowUserPasskey[]>;
|
|
634
|
+
/**
|
|
635
|
+
* Rename a user's passkey to a friendly name.
|
|
636
|
+
*
|
|
637
|
+
* @param name - New friendly name for the passkey
|
|
638
|
+
* @param passkeyId - ID of the passkey to rename
|
|
639
|
+
* @returns Promise with success response
|
|
640
|
+
* @throws {PassflowError} If request fails
|
|
641
|
+
*
|
|
642
|
+
* @example
|
|
643
|
+
* ```typescript
|
|
644
|
+
* await passflow.renameUserPasskey('My MacBook Pro', 'passkey-123');
|
|
645
|
+
* console.log('Passkey renamed successfully');
|
|
646
|
+
* ```
|
|
647
|
+
*/
|
|
66
648
|
renameUserPasskey(name: string, passkeyId: string): Promise<PassflowSuccessResponse>;
|
|
649
|
+
/**
|
|
650
|
+
* Delete a passkey from the user's account.
|
|
651
|
+
*
|
|
652
|
+
* @param passkeyId - ID of the passkey to delete
|
|
653
|
+
* @returns Promise with success response
|
|
654
|
+
* @throws {PassflowError} If request fails
|
|
655
|
+
*
|
|
656
|
+
* @example
|
|
657
|
+
* ```typescript
|
|
658
|
+
* await passflow.deleteUserPasskey('passkey-123');
|
|
659
|
+
* console.log('Passkey deleted successfully');
|
|
660
|
+
* ```
|
|
661
|
+
*/
|
|
67
662
|
deleteUserPasskey(passkeyId: string): Promise<PassflowSuccessResponse>;
|
|
663
|
+
/**
|
|
664
|
+
* Add a new passkey to the current user's account (requires active session).
|
|
665
|
+
*
|
|
666
|
+
* @param options - Optional passkey configuration
|
|
667
|
+
* @param options.relyingPartyId - Optional RP ID for the passkey
|
|
668
|
+
* @param options.passkeyUsername - Optional username to associate with passkey
|
|
669
|
+
* @param options.passkeyDisplayName - Optional display name for the passkey
|
|
670
|
+
* @returns Promise that resolves when passkey is added
|
|
671
|
+
* @throws {PassflowError} If request fails
|
|
672
|
+
*
|
|
673
|
+
* @example
|
|
674
|
+
* ```typescript
|
|
675
|
+
* // Add passkey with default settings
|
|
676
|
+
* await passflow.addUserPasskey();
|
|
677
|
+
*
|
|
678
|
+
* // Add passkey with custom display name
|
|
679
|
+
* await passflow.addUserPasskey({
|
|
680
|
+
* passkeyDisplayName: 'My iPhone'
|
|
681
|
+
* });
|
|
682
|
+
* ```
|
|
683
|
+
*/
|
|
68
684
|
addUserPasskey(options?: {
|
|
69
685
|
relyingPartyId?: string;
|
|
70
686
|
passkeyUsername?: string;
|
|
@@ -84,6 +700,26 @@ export declare class Passflow {
|
|
|
84
700
|
* @returns Promise with tenant response
|
|
85
701
|
*/
|
|
86
702
|
createTenant(name: string, refreshToken?: boolean): Promise<PassflowTenantResponse>;
|
|
703
|
+
/**
|
|
704
|
+
* Request an invitation link for a user to join a tenant.
|
|
705
|
+
*
|
|
706
|
+
* @param payload - Invitation request configuration
|
|
707
|
+
* @param payload.email - Email address to send invitation to
|
|
708
|
+
* @param payload.tenantID - Tenant ID for the invitation
|
|
709
|
+
* @param payload.send_to_email - Whether to send email automatically (default: true)
|
|
710
|
+
* @returns Promise with invitation link response
|
|
711
|
+
* @throws {PassflowError} If request fails
|
|
712
|
+
*
|
|
713
|
+
* @example
|
|
714
|
+
* ```typescript
|
|
715
|
+
* const invitation = await passflow.requestInviteLink({
|
|
716
|
+
* email: 'newuser@example.com',
|
|
717
|
+
* tenantID: 'tenant-123',
|
|
718
|
+
* send_to_email: true
|
|
719
|
+
* });
|
|
720
|
+
* console.log('Invitation link:', invitation.link);
|
|
721
|
+
* ```
|
|
722
|
+
*/
|
|
87
723
|
requestInviteLink(payload: RequestInviteLinkPayload): Promise<InviteLinkResponse>;
|
|
88
724
|
/**
|
|
89
725
|
* Gets a list of active invitations
|
|
@@ -96,20 +732,345 @@ export declare class Passflow {
|
|
|
96
732
|
skip?: number | string;
|
|
97
733
|
limit?: number | string;
|
|
98
734
|
}): Promise<InvitationsPaginatedList>;
|
|
735
|
+
/**
|
|
736
|
+
* Delete an invitation by its token.
|
|
737
|
+
*
|
|
738
|
+
* @param token - Invitation token to delete
|
|
739
|
+
* @returns Promise with success response
|
|
740
|
+
* @throws {PassflowError} If request fails
|
|
741
|
+
*
|
|
742
|
+
* @example
|
|
743
|
+
* ```typescript
|
|
744
|
+
* await passflow.deleteInvitation('invitation-token-123');
|
|
745
|
+
* console.log('Invitation deleted');
|
|
746
|
+
* ```
|
|
747
|
+
*/
|
|
99
748
|
deleteInvitation(token: string): Promise<PassflowSuccessResponse>;
|
|
749
|
+
/**
|
|
750
|
+
* Resend an invitation email.
|
|
751
|
+
*
|
|
752
|
+
* @param token - Invitation token to resend
|
|
753
|
+
* @returns Promise with success response
|
|
754
|
+
* @throws {PassflowError} If request fails
|
|
755
|
+
*
|
|
756
|
+
* @example
|
|
757
|
+
* ```typescript
|
|
758
|
+
* await passflow.resendInvitation('invitation-token-123');
|
|
759
|
+
* console.log('Invitation email resent');
|
|
760
|
+
* ```
|
|
761
|
+
*/
|
|
100
762
|
resendInvitation(token: string): Promise<PassflowSuccessResponse>;
|
|
763
|
+
/**
|
|
764
|
+
* Get invitation details and link by invitation ID.
|
|
765
|
+
*
|
|
766
|
+
* @param invitationID - Invitation ID to retrieve
|
|
767
|
+
* @returns Promise with invitation link response
|
|
768
|
+
* @throws {PassflowError} If request fails
|
|
769
|
+
*
|
|
770
|
+
* @example
|
|
771
|
+
* ```typescript
|
|
772
|
+
* const invitation = await passflow.getInvitationLink('invitation-123');
|
|
773
|
+
* console.log('Invitation link:', invitation.link);
|
|
774
|
+
* ```
|
|
775
|
+
*/
|
|
101
776
|
getInvitationLink(invitationID: string): Promise<InviteLinkResponse>;
|
|
777
|
+
/**
|
|
778
|
+
* Generate an authentication redirect URL for hosted login.
|
|
779
|
+
*
|
|
780
|
+
* @param options - Redirect URL configuration
|
|
781
|
+
* @param options.url - Optional custom Passflow server URL
|
|
782
|
+
* @param options.redirectUrl - URL to redirect to after authentication
|
|
783
|
+
* @param options.scopes - Optional scopes to request
|
|
784
|
+
* @param options.appId - Optional app ID to use
|
|
785
|
+
* @returns Authentication redirect URL
|
|
786
|
+
*
|
|
787
|
+
* @example
|
|
788
|
+
* ```typescript
|
|
789
|
+
* const authUrl = passflow.authRedirectUrl({
|
|
790
|
+
* redirectUrl: window.location.origin + '/auth/callback',
|
|
791
|
+
* scopes: ['id', 'email', 'offline']
|
|
792
|
+
* });
|
|
793
|
+
* console.log('Auth URL:', authUrl);
|
|
794
|
+
* // Use this URL for custom navigation logic
|
|
795
|
+
* ```
|
|
796
|
+
*/
|
|
102
797
|
authRedirectUrl(options?: {
|
|
103
798
|
url?: string;
|
|
104
799
|
redirectUrl?: string;
|
|
105
800
|
scopes?: string[];
|
|
106
801
|
appId?: string;
|
|
107
802
|
}): string;
|
|
803
|
+
/**
|
|
804
|
+
* Redirect to the Passflow hosted login page.
|
|
805
|
+
*
|
|
806
|
+
* @param options - Redirect configuration
|
|
807
|
+
* @param options.url - Optional custom Passflow server URL
|
|
808
|
+
* @param options.redirectUrl - URL to redirect to after authentication
|
|
809
|
+
* @param options.scopes - Optional scopes to request
|
|
810
|
+
* @param options.appId - Optional app ID to use
|
|
811
|
+
*
|
|
812
|
+
* @example
|
|
813
|
+
* ```typescript
|
|
814
|
+
* // Redirect to hosted login page
|
|
815
|
+
* passflow.authRedirect({
|
|
816
|
+
* redirectUrl: window.location.origin + '/auth/callback'
|
|
817
|
+
* });
|
|
818
|
+
* ```
|
|
819
|
+
*/
|
|
108
820
|
authRedirect(options?: {
|
|
109
821
|
url?: string;
|
|
110
822
|
redirectUrl?: string;
|
|
111
823
|
scopes?: string[];
|
|
112
824
|
appId?: string;
|
|
113
825
|
}): void;
|
|
826
|
+
/**
|
|
827
|
+
* Get the current token delivery mode.
|
|
828
|
+
* Returns the mode determined by the server (json_body, cookie, or mobile).
|
|
829
|
+
*
|
|
830
|
+
* @returns The current token delivery mode
|
|
831
|
+
*
|
|
832
|
+
* @example
|
|
833
|
+
* ```typescript
|
|
834
|
+
* import { TokenDeliveryMode } from '@passflow/core';
|
|
835
|
+
*
|
|
836
|
+
* const mode = passflow.getDeliveryMode();
|
|
837
|
+
* if (mode === TokenDeliveryMode.Cookie) {
|
|
838
|
+
* console.log('Using cookie-based authentication');
|
|
839
|
+
* } else {
|
|
840
|
+
* console.log('Using JSON body authentication');
|
|
841
|
+
* }
|
|
842
|
+
* ```
|
|
843
|
+
*/
|
|
844
|
+
getDeliveryMode(): import('./token/delivery-manager').TokenDeliveryMode;
|
|
845
|
+
/**
|
|
846
|
+
* Restore and validate session for cookie mode on page load.
|
|
847
|
+
* Only applicable when using cookie-based token delivery.
|
|
848
|
+
* Validates that HttpOnly cookies are still valid with the server.
|
|
849
|
+
*
|
|
850
|
+
* This method is automatically called on SDK initialization for cookie mode,
|
|
851
|
+
* but can be called manually to re-validate the session.
|
|
852
|
+
*
|
|
853
|
+
* @returns Promise resolving to true if session is valid, false otherwise
|
|
854
|
+
*
|
|
855
|
+
* @example
|
|
856
|
+
* ```typescript
|
|
857
|
+
* // Check if session is valid (useful after page reload)
|
|
858
|
+
* const isValid = await passflow.restoreSession();
|
|
859
|
+
* if (isValid) {
|
|
860
|
+
* console.log('Session restored successfully');
|
|
861
|
+
* } else {
|
|
862
|
+
* console.log('Session expired, please sign in again');
|
|
863
|
+
* }
|
|
864
|
+
* ```
|
|
865
|
+
*/
|
|
866
|
+
restoreSession(): Promise<boolean>;
|
|
867
|
+
/**
|
|
868
|
+
* Get the current 2FA enrollment status for the authenticated user.
|
|
869
|
+
*
|
|
870
|
+
* @returns Promise with 2FA status including enabled state and policy
|
|
871
|
+
* @throws {PassflowError} If request fails
|
|
872
|
+
*
|
|
873
|
+
* @example
|
|
874
|
+
* ```typescript
|
|
875
|
+
* const status = await passflow.getTwoFactorStatus();
|
|
876
|
+
* console.log('2FA enabled:', status.enabled);
|
|
877
|
+
* console.log('Recovery codes remaining:', status.recovery_codes_remaining);
|
|
878
|
+
* ```
|
|
879
|
+
*/
|
|
880
|
+
getTwoFactorStatus(): Promise<TwoFactorStatusResponse>;
|
|
881
|
+
/**
|
|
882
|
+
* Begin the 2FA setup process for the authenticated user.
|
|
883
|
+
* Returns a secret and QR code to scan with an authenticator app.
|
|
884
|
+
*
|
|
885
|
+
* @returns Promise with setup response containing secret and QR code
|
|
886
|
+
* @throws {PassflowError} If request fails
|
|
887
|
+
*
|
|
888
|
+
* @example
|
|
889
|
+
* ```typescript
|
|
890
|
+
* const setup = await passflow.beginTwoFactorSetup();
|
|
891
|
+
* console.log('Scan this QR code:', setup.qr_code);
|
|
892
|
+
* console.log('Or enter this secret:', setup.secret);
|
|
893
|
+
* ```
|
|
894
|
+
*/
|
|
895
|
+
beginTwoFactorSetup(): Promise<TwoFactorSetupResponse>;
|
|
896
|
+
/**
|
|
897
|
+
* Confirm 2FA setup by verifying a TOTP code from the authenticator app.
|
|
898
|
+
* Returns recovery codes that MUST be saved by the user.
|
|
899
|
+
*
|
|
900
|
+
* @param code - 6-digit TOTP code from authenticator app
|
|
901
|
+
* @returns Promise with confirmation response including recovery codes
|
|
902
|
+
* @throws {PassflowError} If verification fails
|
|
903
|
+
*
|
|
904
|
+
* @example
|
|
905
|
+
* ```typescript
|
|
906
|
+
* const result = await passflow.confirmTwoFactorSetup('123456');
|
|
907
|
+
* console.log('SAVE THESE RECOVERY CODES:', result.recovery_codes);
|
|
908
|
+
* // Display recovery codes to user for safekeeping
|
|
909
|
+
* ```
|
|
910
|
+
*/
|
|
911
|
+
confirmTwoFactorSetup(code: string): Promise<TwoFactorConfirmResponse>;
|
|
912
|
+
/**
|
|
913
|
+
* Verify a TOTP code during login when 2FA is required.
|
|
914
|
+
* Completes the authentication process and saves tokens.
|
|
915
|
+
*
|
|
916
|
+
* @param code - 6-digit TOTP code from authenticator app
|
|
917
|
+
* @returns Promise with verification response containing tokens
|
|
918
|
+
* @throws {PassflowError} If verification fails
|
|
919
|
+
*
|
|
920
|
+
* @example
|
|
921
|
+
* ```typescript
|
|
922
|
+
* // After signIn returns requires_2fa: true
|
|
923
|
+
* if (passflow.isTwoFactorVerificationRequired()) {
|
|
924
|
+
* const response = await passflow.verifyTwoFactor('123456');
|
|
925
|
+
* console.log('Authentication complete', response.access_token);
|
|
926
|
+
* }
|
|
927
|
+
* ```
|
|
928
|
+
*/
|
|
929
|
+
verifyTwoFactor(code: string): Promise<TwoFactorVerifyResponse>;
|
|
930
|
+
/**
|
|
931
|
+
* Use a recovery code for authentication when TOTP is unavailable.
|
|
932
|
+
* Completes the authentication process and saves tokens.
|
|
933
|
+
*
|
|
934
|
+
* @param code - Recovery code from the list provided during setup
|
|
935
|
+
* @returns Promise with recovery response containing tokens and remaining codes count
|
|
936
|
+
* @throws {PassflowError} If recovery code is invalid
|
|
937
|
+
*
|
|
938
|
+
* @example
|
|
939
|
+
* ```typescript
|
|
940
|
+
* // After signIn returns requires_2fa: true
|
|
941
|
+
* const result = await passflow.useTwoFactorRecoveryCode('ABCD-1234');
|
|
942
|
+
* console.log('Authenticated with recovery code');
|
|
943
|
+
* console.log(`${result.remaining_recovery_codes} recovery codes remaining`);
|
|
944
|
+
* ```
|
|
945
|
+
*/
|
|
946
|
+
useTwoFactorRecoveryCode(code: string): Promise<TwoFactorRecoveryResponse>;
|
|
947
|
+
/**
|
|
948
|
+
* Disable 2FA for the authenticated user.
|
|
949
|
+
* Requires verification with a current TOTP code.
|
|
950
|
+
*
|
|
951
|
+
* @param code - Current 6-digit TOTP code for verification
|
|
952
|
+
* @returns Promise with success response
|
|
953
|
+
* @throws {PassflowError} If verification fails
|
|
954
|
+
*
|
|
955
|
+
* @example
|
|
956
|
+
* ```typescript
|
|
957
|
+
* await passflow.disableTwoFactor('123456');
|
|
958
|
+
* console.log('2FA disabled successfully');
|
|
959
|
+
* ```
|
|
960
|
+
*/
|
|
961
|
+
disableTwoFactor(code: string): Promise<TwoFactorDisableResponse>;
|
|
962
|
+
/**
|
|
963
|
+
* Regenerate recovery codes for the authenticated user.
|
|
964
|
+
* Old recovery codes will be invalidated. Requires verification with a current TOTP code.
|
|
965
|
+
*
|
|
966
|
+
* @param code - Current 6-digit TOTP code for verification
|
|
967
|
+
* @returns Promise with response containing new recovery codes
|
|
968
|
+
* @throws {PassflowError} If verification fails
|
|
969
|
+
*
|
|
970
|
+
* @example
|
|
971
|
+
* ```typescript
|
|
972
|
+
* const result = await passflow.regenerateTwoFactorRecoveryCodes('123456');
|
|
973
|
+
* console.log('New recovery codes:', result.recovery_codes);
|
|
974
|
+
* // Display new recovery codes to user for safekeeping
|
|
975
|
+
* ```
|
|
976
|
+
*/
|
|
977
|
+
regenerateTwoFactorRecoveryCodes(code: string): Promise<TwoFactorRegenerateResponse>;
|
|
978
|
+
/**
|
|
979
|
+
* Check if 2FA verification is currently required (local state check).
|
|
980
|
+
* Returns true if user has signed in but needs to complete 2FA verification.
|
|
981
|
+
*
|
|
982
|
+
* @returns True if 2FA verification is pending, false otherwise
|
|
983
|
+
*
|
|
984
|
+
* @example
|
|
985
|
+
* ```typescript
|
|
986
|
+
* if (passflow.isTwoFactorVerificationRequired()) {
|
|
987
|
+
* // Show 2FA code input UI
|
|
988
|
+
* console.log('Please enter your 2FA code');
|
|
989
|
+
* }
|
|
990
|
+
* ```
|
|
991
|
+
*/
|
|
992
|
+
isTwoFactorVerificationRequired(): boolean;
|
|
993
|
+
/**
|
|
994
|
+
* Get configured TOTP digit count for the current app
|
|
995
|
+
* @returns Number of digits (6 or 8) configured for TOTP codes
|
|
996
|
+
*
|
|
997
|
+
* @example
|
|
998
|
+
* ```typescript
|
|
999
|
+
* const digits = passflow.getTotpDigits();
|
|
1000
|
+
* console.log(`TOTP codes should be ${digits} digits`);
|
|
1001
|
+
* ```
|
|
1002
|
+
*/
|
|
1003
|
+
getTotpDigits(): 6 | 8;
|
|
1004
|
+
/**
|
|
1005
|
+
* Validate a magic link token for 2FA setup.
|
|
1006
|
+
* Used when a user clicks on an admin-generated magic link to set up 2FA.
|
|
1007
|
+
*
|
|
1008
|
+
* The magic link creates a scoped session that can ONLY be used for 2FA setup,
|
|
1009
|
+
* not for regular authentication.
|
|
1010
|
+
*
|
|
1011
|
+
* @param token - Magic link token from URL parameter
|
|
1012
|
+
* @returns Promise with validation response containing scoped session or error
|
|
1013
|
+
*
|
|
1014
|
+
* @example
|
|
1015
|
+
* ```typescript
|
|
1016
|
+
* // On the magic link landing page (e.g., /2fa-setup/:token)
|
|
1017
|
+
* const urlToken = extractTokenFromUrl();
|
|
1018
|
+
* const result = await passflow.validateTwoFactorSetupMagicLink(urlToken);
|
|
1019
|
+
*
|
|
1020
|
+
* if (result.success) {
|
|
1021
|
+
* console.log('Magic link validated');
|
|
1022
|
+
* console.log('User ID:', result.userId);
|
|
1023
|
+
* console.log('Session expires in:', result.expiresIn, 'seconds');
|
|
1024
|
+
* // Show 2FA setup form
|
|
1025
|
+
* } else {
|
|
1026
|
+
* console.error('Validation failed:', result.error?.message);
|
|
1027
|
+
* // Show error UI
|
|
1028
|
+
* }
|
|
1029
|
+
* ```
|
|
1030
|
+
*/
|
|
1031
|
+
validateTwoFactorSetupMagicLink(token: string): Promise<import('./api/model').TwoFactorSetupMagicLinkValidationResponse>;
|
|
1032
|
+
/**
|
|
1033
|
+
* Get the current magic link session (if any).
|
|
1034
|
+
* Used by React SDK components to access session data.
|
|
1035
|
+
*
|
|
1036
|
+
* @returns Active magic link session or null if none/expired
|
|
1037
|
+
*
|
|
1038
|
+
* @example
|
|
1039
|
+
* ```typescript
|
|
1040
|
+
* const session = passflow.getMagicLinkSession();
|
|
1041
|
+
* if (session) {
|
|
1042
|
+
* console.log('Active session for user:', session.userId);
|
|
1043
|
+
* console.log('Expires at:', new Date(session.expiresAt));
|
|
1044
|
+
* }
|
|
1045
|
+
* ```
|
|
1046
|
+
*/
|
|
1047
|
+
getMagicLinkSession(): import('./api/model').TwoFactorSetupMagicLinkSession | null;
|
|
1048
|
+
/**
|
|
1049
|
+
* Check if a magic link session is currently active.
|
|
1050
|
+
*
|
|
1051
|
+
* @returns True if magic link session is active and not expired
|
|
1052
|
+
*
|
|
1053
|
+
* @example
|
|
1054
|
+
* ```typescript
|
|
1055
|
+
* if (passflow.hasMagicLinkSession()) {
|
|
1056
|
+
* // User can proceed with 2FA setup
|
|
1057
|
+
* } else {
|
|
1058
|
+
* // Redirect to error page or request new link
|
|
1059
|
+
* }
|
|
1060
|
+
* ```
|
|
1061
|
+
*/
|
|
1062
|
+
hasMagicLinkSession(): boolean;
|
|
1063
|
+
/**
|
|
1064
|
+
* Clear the magic link session.
|
|
1065
|
+
* Called after successful 2FA setup or on error.
|
|
1066
|
+
*
|
|
1067
|
+
* @example
|
|
1068
|
+
* ```typescript
|
|
1069
|
+
* // After 2FA setup is complete
|
|
1070
|
+
* passflow.clearMagicLinkSession();
|
|
1071
|
+
* // Redirect to sign-in
|
|
1072
|
+
* ```
|
|
1073
|
+
*/
|
|
1074
|
+
clearMagicLinkSession(): void;
|
|
114
1075
|
}
|
|
115
1076
|
//# sourceMappingURL=passflow.d.ts.map
|