@bagelink/auth 1.4.178 → 1.4.182

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.d.mts CHANGED
@@ -1,4 +1,4 @@
1
- import { AxiosResponse, AxiosInstance } from 'axios';
1
+ import { AxiosResponse } from 'axios';
2
2
  import * as vue from 'vue';
3
3
  import { App } from 'vue';
4
4
 
@@ -27,6 +27,7 @@ interface AuthEventMap {
27
27
  }
28
28
  type AuthenticationAccountType = 'person' | 'entity' | 'service';
29
29
  type AuthenticationMethodType = 'password' | 'email_token' | 'sso' | 'otp';
30
+ type SSOProvider = 'google' | 'microsoft' | 'github' | 'okta' | 'apple' | 'facebook';
30
31
  interface AuthenticationAccount {
31
32
  created_at?: string;
32
33
  updated_at?: string;
@@ -55,6 +56,8 @@ interface AuthMethodInfo {
55
56
  is_verified: boolean;
56
57
  last_used?: string;
57
58
  use_count: number;
59
+ provider?: SSOProvider;
60
+ provider_user_id?: string;
58
61
  }
59
62
  interface AccountInfo {
60
63
  id: string;
@@ -171,12 +174,33 @@ interface OTPMetadata {
171
174
  };
172
175
  }
173
176
  interface SSOMetadata {
174
- provider: string;
177
+ provider: SSOProvider;
175
178
  sso_user_info: {
176
179
  [key: string]: any;
177
180
  };
178
181
  can_create_account?: boolean;
179
182
  }
183
+ interface SSOInitiateRequest {
184
+ provider: SSOProvider;
185
+ redirect_uri?: string;
186
+ state?: string;
187
+ scopes?: string[];
188
+ params?: Record<string, string>;
189
+ code_challenge?: string;
190
+ code_challenge_method?: 'S256' | 'plain';
191
+ }
192
+ interface SSOCallbackRequest {
193
+ provider: SSOProvider;
194
+ code: string;
195
+ state?: string;
196
+ }
197
+ interface SSOLinkRequest {
198
+ provider: SSOProvider;
199
+ code: string;
200
+ }
201
+ interface SSOUnlinkRequest {
202
+ provider: SSOProvider;
203
+ }
180
204
  interface AuthenticationResponse {
181
205
  success: boolean;
182
206
  account_id?: string;
@@ -215,6 +239,12 @@ type DeleteSessionResponse = AxiosResponse<MessageResponse>;
215
239
  type DeleteAllSessionsResponse = AxiosResponse<MessageResponse>;
216
240
  type CleanupSessionsResponse = AxiosResponse<MessageResponse>;
217
241
  type GetMethodsResponse = AxiosResponse<AvailableMethodsResponse>;
242
+ type SSOInitiateResponse = AxiosResponse<{
243
+ authorization_url: string;
244
+ }>;
245
+ type SSOCallbackResponse = AxiosResponse<AuthenticationResponse>;
246
+ type SSOLinkResponse = AxiosResponse<MessageResponse>;
247
+ type SSOUnlinkResponse = AxiosResponse<MessageResponse>;
218
248
  /**
219
249
  * Extract unified user from account info
220
250
  */
@@ -222,7 +252,7 @@ declare function accountToUser(account: AccountInfo | null): User | null;
222
252
 
223
253
  declare class AuthApi {
224
254
  private api;
225
- constructor(axiosInstance?: AxiosInstance, baseURL?: string);
255
+ constructor(baseURL?: string);
226
256
  private setupInterceptors;
227
257
  /**
228
258
  * Get available authentication methods
@@ -244,6 +274,23 @@ declare class AuthApi {
244
274
  * Refresh current session
245
275
  */
246
276
  refreshSession(): Promise<RefreshSessionResponse>;
277
+ /**
278
+ * Initiate SSO login flow
279
+ * Returns authorization URL to redirect user to
280
+ */
281
+ initiateSSO(data: SSOInitiateRequest): Promise<SSOInitiateResponse>;
282
+ /**
283
+ * Complete SSO login after callback from provider
284
+ */
285
+ ssoCallback(data: SSOCallbackRequest): Promise<SSOCallbackResponse>;
286
+ /**
287
+ * Link an SSO provider to existing account
288
+ */
289
+ linkSSOProvider(data: SSOLinkRequest): Promise<SSOLinkResponse>;
290
+ /**
291
+ * Unlink an SSO provider from account
292
+ */
293
+ unlinkSSOProvider(provider: SSOProvider): Promise<SSOUnlinkResponse>;
247
294
  /**
248
295
  * Get current user account info
249
296
  */
@@ -318,9 +365,217 @@ declare class AuthApi {
318
365
  cleanupSessions(): Promise<CleanupSessionsResponse>;
319
366
  }
320
367
 
321
- declare function initAuth({ axios, baseURL, }: {
322
- axios: AxiosInstance;
323
- baseURL?: string;
368
+ /**
369
+ * Set the auth context for SSO operations
370
+ * This is called automatically when using useAuth()
371
+ */
372
+ declare function setAuthContext(authApi: any): void;
373
+ /**
374
+ * SSO Provider Configuration
375
+ */
376
+ interface SSOProviderConfig {
377
+ /** Provider identifier */
378
+ id: SSOProvider;
379
+ /** Display name */
380
+ name: string;
381
+ /** Brand color (hex) */
382
+ color: string;
383
+ /** Icon identifier (for UI libraries) */
384
+ icon: string;
385
+ /** Default OAuth scopes */
386
+ defaultScopes: string[];
387
+ /** Provider-specific metadata */
388
+ metadata?: {
389
+ authDomain?: string;
390
+ buttonText?: string;
391
+ [key: string]: any;
392
+ };
393
+ }
394
+ /**
395
+ * OAuth Flow Options
396
+ */
397
+ interface OAuthFlowOptions {
398
+ /** Custom redirect URI (defaults to current origin + /auth/callback) */
399
+ redirectUri?: string;
400
+ /** State parameter for CSRF protection (auto-generated if not provided) */
401
+ state?: string;
402
+ /** Custom scopes (overrides provider defaults) */
403
+ scopes?: string[];
404
+ /** Additional OAuth parameters (prompt, login_hint, hd, domain, etc.) */
405
+ params?: Record<string, string>;
406
+ /** Popup window dimensions */
407
+ popupDimensions?: {
408
+ width?: number;
409
+ height?: number;
410
+ };
411
+ /** Timeout for popup flow in milliseconds (default: 90000) */
412
+ popupTimeout?: number;
413
+ }
414
+ /**
415
+ * Popup Result
416
+ */
417
+ interface PopupResult {
418
+ code: string;
419
+ state?: string;
420
+ error?: string;
421
+ }
422
+ /**
423
+ * SSO Error Types
424
+ */
425
+ declare class SSOError extends Error {
426
+ code: string;
427
+ constructor(message: string, code: string);
428
+ }
429
+ declare class PopupBlockedError extends SSOError {
430
+ constructor();
431
+ }
432
+ declare class PopupClosedError extends SSOError {
433
+ constructor();
434
+ }
435
+ declare class PopupTimeoutError extends SSOError {
436
+ constructor();
437
+ }
438
+ declare class StateMismatchError extends SSOError {
439
+ constructor();
440
+ }
441
+ /**
442
+ * SSO Provider Instance with functional methods
443
+ */
444
+ interface SSOProviderInstance extends SSOProviderConfig {
445
+ /**
446
+ * Initiate OAuth flow with redirect (most common)
447
+ * User is redirected to provider's authorization page
448
+ */
449
+ redirect: (options?: OAuthFlowOptions) => Promise<void>;
450
+ /**
451
+ * Initiate OAuth flow in a popup window
452
+ * Returns the authorization code without leaving the page
453
+ */
454
+ popup: (options?: OAuthFlowOptions) => Promise<AuthenticationResponse>;
455
+ /**
456
+ * Complete OAuth flow after callback
457
+ * Call this on your callback page
458
+ */
459
+ callback: (code: string, state?: string) => Promise<AuthenticationResponse>;
460
+ /**
461
+ * Link this provider to the current logged-in user
462
+ */
463
+ link: (code: string) => Promise<void>;
464
+ /**
465
+ * Unlink this provider from the current user
466
+ */
467
+ unlink: () => Promise<void>;
468
+ /**
469
+ * Get authorization URL without redirecting
470
+ */
471
+ getAuthUrl: (options?: OAuthFlowOptions) => Promise<string>;
472
+ /**
473
+ * Whether this provider supports popup flow
474
+ * Some providers (like Apple) work better with redirect
475
+ */
476
+ supportsPopup?: boolean;
477
+ }
478
+ /**
479
+ * SSO Provider Implementations
480
+ */
481
+ declare const sso: {
482
+ /**
483
+ * Google OAuth Provider
484
+ * https://developers.google.com/identity/protocols/oauth2
485
+ */
486
+ google: SSOProviderInstance;
487
+ /**
488
+ * Microsoft OAuth Provider (Azure AD / Microsoft Entra ID)
489
+ * https://learn.microsoft.com/en-us/azure/active-directory/develop/v2-oauth2-auth-code-flow
490
+ */
491
+ microsoft: SSOProviderInstance;
492
+ /**
493
+ * GitHub OAuth Provider
494
+ * https://docs.github.com/en/apps/oauth-apps/building-oauth-apps/authorizing-oauth-apps
495
+ */
496
+ github: SSOProviderInstance;
497
+ /**
498
+ * Okta OAuth Provider
499
+ * https://developer.okta.com/docs/guides/implement-grant-type/authcode/main/
500
+ */
501
+ okta: SSOProviderInstance;
502
+ /**
503
+ * Apple Sign In Provider
504
+ * https://developer.apple.com/documentation/sign_in_with_apple/sign_in_with_apple_rest_api
505
+ * Note: Apple works best with redirect flow on web
506
+ */
507
+ apple: {
508
+ supportsPopup: boolean;
509
+ popup(options?: OAuthFlowOptions): Promise<any>;
510
+ /**
511
+ * Initiate OAuth flow with redirect (most common)
512
+ * User is redirected to provider's authorization page
513
+ */
514
+ redirect: (options?: OAuthFlowOptions) => Promise<void>;
515
+ /**
516
+ * Complete OAuth flow after callback
517
+ * Call this on your callback page
518
+ */
519
+ callback: (code: string, state?: string) => Promise<AuthenticationResponse>;
520
+ /**
521
+ * Link this provider to the current logged-in user
522
+ */
523
+ link: (code: string) => Promise<void>;
524
+ /**
525
+ * Unlink this provider from the current user
526
+ */
527
+ unlink: () => Promise<void>;
528
+ /**
529
+ * Get authorization URL without redirecting
530
+ */
531
+ getAuthUrl: (options?: OAuthFlowOptions) => Promise<string>;
532
+ /** Provider identifier */
533
+ id: SSOProvider;
534
+ /** Display name */
535
+ name: string;
536
+ /** Brand color (hex) */
537
+ color: string;
538
+ /** Icon identifier (for UI libraries) */
539
+ icon: string;
540
+ /** Default OAuth scopes */
541
+ defaultScopes: string[];
542
+ /** Provider-specific metadata */
543
+ metadata?: {
544
+ authDomain?: string;
545
+ buttonText?: string;
546
+ [key: string]: any;
547
+ };
548
+ };
549
+ /**
550
+ * Facebook OAuth Provider
551
+ * https://developers.facebook.com/docs/facebook-login/guides/advanced/manual-flow
552
+ */
553
+ facebook: SSOProviderInstance;
554
+ };
555
+ /**
556
+ * Array of all SSO providers
557
+ */
558
+ declare const ssoProviders: readonly SSOProviderInstance[];
559
+ /**
560
+ * Get SSO provider instance by ID
561
+ */
562
+ declare function getSSOProvider(provider: SSOProvider): SSOProviderInstance | undefined;
563
+ /**
564
+ * Get all available SSO providers
565
+ */
566
+ declare function getAllSSOProviders(): readonly SSOProviderInstance[];
567
+ /**
568
+ * Check if a provider is supported
569
+ */
570
+ declare function isSupportedProvider(provider: string): provider is SSOProvider;
571
+ /**
572
+ * Handle OAuth callback from URL
573
+ * Call this on your callback page to automatically detect and process the callback
574
+ */
575
+ declare function handleOAuthCallback(): Promise<AuthenticationResponse | null>;
576
+
577
+ declare function initAuth({ baseURL, }: {
578
+ baseURL: string;
324
579
  }): {
325
580
  on<K extends AuthState>(event: K, handler: AuthEventMap[K]): void;
326
581
  off<K extends AuthState>(event: K, handler: AuthEventMap[K]): void;
@@ -343,6 +598,8 @@ declare function useAuth(): {
343
598
  is_verified: boolean;
344
599
  last_used?: string | undefined;
345
600
  use_count: number;
601
+ provider?: SSOProvider | undefined;
602
+ provider_user_id?: string | undefined;
346
603
  }[];
347
604
  person?: {
348
605
  id: string;
@@ -370,6 +627,8 @@ declare function useAuth(): {
370
627
  is_verified: boolean;
371
628
  last_used?: string | undefined;
372
629
  use_count: number;
630
+ provider?: SSOProvider | undefined;
631
+ provider_user_id?: string | undefined;
373
632
  }[];
374
633
  person?: {
375
634
  id: string;
@@ -384,6 +643,32 @@ declare function useAuth(): {
384
643
  metadata?: Record<string, any> | undefined;
385
644
  } | undefined;
386
645
  } | null>;
646
+ sso: {
647
+ google: SSOProviderInstance;
648
+ microsoft: SSOProviderInstance;
649
+ github: SSOProviderInstance;
650
+ okta: SSOProviderInstance;
651
+ apple: {
652
+ supportsPopup: boolean;
653
+ popup(options?: OAuthFlowOptions): Promise<any>;
654
+ redirect: (options?: OAuthFlowOptions) => Promise<void>;
655
+ callback: (code: string, state?: string) => Promise<AuthenticationResponse>;
656
+ link: (code: string) => Promise<void>;
657
+ unlink: () => Promise<void>;
658
+ getAuthUrl: (options?: OAuthFlowOptions) => Promise<string>;
659
+ id: SSOProvider;
660
+ name: string;
661
+ color: string;
662
+ icon: string;
663
+ defaultScopes: string[];
664
+ metadata?: {
665
+ authDomain?: string;
666
+ buttonText?: string;
667
+ [key: string]: any;
668
+ };
669
+ };
670
+ facebook: SSOProviderInstance;
671
+ };
387
672
  getFullName: () => string;
388
673
  getIsLoggedIn: () => boolean;
389
674
  getEmail: () => string;
@@ -399,6 +684,10 @@ declare function useAuth(): {
399
684
  signup: (newUser: NewUser) => Promise<AuthenticationResponse>;
400
685
  checkAuth: () => Promise<boolean>;
401
686
  refreshSession: () => Promise<void>;
687
+ initiateSSO: (params: SSOInitiateRequest) => Promise<string>;
688
+ loginWithSSO: (params: SSOCallbackRequest) => Promise<AuthenticationResponse>;
689
+ linkSSOProvider: (params: SSOLinkRequest) => Promise<void>;
690
+ unlinkSSOProvider: (provider: SSOProvider) => Promise<void>;
402
691
  updateProfile: (updates: UpdateAccountRequest) => Promise<void>;
403
692
  deleteCurrentUser: () => Promise<void>;
404
693
  changePassword: (form: UpdatePasswordForm) => Promise<void>;
@@ -415,5 +704,5 @@ declare function useAuth(): {
415
704
  revokeAllSessions: (accountId?: string) => Promise<void>;
416
705
  };
417
706
 
418
- export { AuthApi, AuthState, accountToUser, initAuth, useAuth };
419
- export type { AccountInfo, ActivateAccountResponse, AuthEventHandler, AuthEventMap, AuthMethodInfo, AuthStatusResponse, AuthenticationAccount, AuthenticationAccountType, AuthenticationMethodType, AuthenticationResponse, AvailableMethodsResponse, ChangePasswordRequest, ChangePasswordResponse, CleanupSessionsResponse, DeactivateAccountResponse, DeleteAccountResponse, DeleteAllSessionsResponse, DeleteMeResponse, DeleteSessionResponse, EntityInfo, ForgotPasswordRequest, ForgotPasswordResponse, GetAccountResponse, GetMeResponse, GetMethodsResponse, GetSessionsResponse, LoginResponse, LogoutResponse, MessageResponse, NewUser, OTPMetadata, PasswordLoginRequest, PersonInfo, RefreshSessionResponse, RegisterRequest, RegisterResponse, ResetPasswordRequest, ResetPasswordResponse, SSOMetadata, SendVerificationRequest, SendVerificationResponse, SessionInfo, SessionListResponse, UpdateAccountRequest, UpdateAccountResponse, UpdateMeResponse, UpdatePasswordForm, User, VerifyEmailRequest, VerifyEmailResponse, VerifyResetTokenResponse };
707
+ export { AuthApi, AuthState, PopupBlockedError, PopupClosedError, PopupTimeoutError, SSOError, StateMismatchError, accountToUser, getAllSSOProviders, getSSOProvider, handleOAuthCallback, initAuth, isSupportedProvider, setAuthContext, sso, ssoProviders, useAuth };
708
+ export type { AccountInfo, ActivateAccountResponse, AuthEventHandler, AuthEventMap, AuthMethodInfo, AuthStatusResponse, AuthenticationAccount, AuthenticationAccountType, AuthenticationMethodType, AuthenticationResponse, AvailableMethodsResponse, ChangePasswordRequest, ChangePasswordResponse, CleanupSessionsResponse, DeactivateAccountResponse, DeleteAccountResponse, DeleteAllSessionsResponse, DeleteMeResponse, DeleteSessionResponse, EntityInfo, ForgotPasswordRequest, ForgotPasswordResponse, GetAccountResponse, GetMeResponse, GetMethodsResponse, GetSessionsResponse, LoginResponse, LogoutResponse, MessageResponse, NewUser, OAuthFlowOptions, OTPMetadata, PasswordLoginRequest, PersonInfo, PopupResult, RefreshSessionResponse, RegisterRequest, RegisterResponse, ResetPasswordRequest, ResetPasswordResponse, SSOCallbackRequest, SSOCallbackResponse, SSOInitiateRequest, SSOInitiateResponse, SSOLinkRequest, SSOLinkResponse, SSOMetadata, SSOProvider, SSOProviderConfig, SSOProviderInstance, SSOUnlinkRequest, SSOUnlinkResponse, SendVerificationRequest, SendVerificationResponse, SessionInfo, SessionListResponse, UpdateAccountRequest, UpdateAccountResponse, UpdateMeResponse, UpdatePasswordForm, User, VerifyEmailRequest, VerifyEmailResponse, VerifyResetTokenResponse };