isa-auth 0.2.2 → 0.2.3

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.ts CHANGED
@@ -52,18 +52,42 @@ declare global {
52
52
  google?: any;
53
53
  }
54
54
  }
55
+ interface GoogleAuthOptions {
56
+ clientId: string;
57
+ callback?: (token: string) => string | Promise<string>;
58
+ scope?: string;
59
+ autoPrompt?: boolean;
60
+ redirectUri?: string;
61
+ isPopup?: boolean;
62
+ onSuccess?: (userOrToken: any) => void;
63
+ onFail?: (error: any) => void;
64
+ }
55
65
  declare class GoogleAuthProvider implements AuthProvider$1 {
56
66
  private clientId;
57
- private callback;
58
- constructor({ clientId, callback, }: {
67
+ private callback?;
68
+ private scope;
69
+ private autoPrompt;
70
+ private redirectUri?;
71
+ private isPopup;
72
+ private onSuccess?;
73
+ private onFail?;
74
+ private idToken;
75
+ private accessToken;
76
+ private userInfo;
77
+ private tokenClient;
78
+ private pendingSignIn;
79
+ constructor(options: GoogleAuthOptions | {
59
80
  clientId: string;
60
- callback: (token: string) => string | Promise<string>;
81
+ callback?: (token: string) => string | Promise<string>;
61
82
  });
62
83
  loadGoogleSdk(): Promise<void>;
63
84
  init(): Promise<void>;
64
- signIn(): void;
85
+ handleCredentialResponse(credential: string): void;
86
+ promptOneTap(): void;
87
+ renderGoogleButton(parent: HTMLElement, options?: any): void;
88
+ signIn(): Promise<void>;
65
89
  signOut(): void;
66
- getAccessToken(): Promise<any>;
90
+ getAccessToken(): Promise<string | null>;
67
91
  getUserInfo(): Promise<any>;
68
92
  }
69
93
 
@@ -79,6 +103,7 @@ interface AppleAuthOptions {
79
103
  state?: string;
80
104
  nonce?: string;
81
105
  usePopup?: boolean;
106
+ responseMode?: 'form_post' | 'fragment' | 'query';
82
107
  onSuccess?: (response: any) => void;
83
108
  onFail?: (error: any) => void;
84
109
  }
@@ -87,8 +112,10 @@ declare class AppleAuthProvider implements AuthProvider$1 {
87
112
  private redirectURI;
88
113
  private scope;
89
114
  private state?;
115
+ private lastState?;
90
116
  private nonce?;
91
117
  private usePopup;
118
+ private responseMode?;
92
119
  private onSuccess?;
93
120
  private onFail?;
94
121
  private idToken;
@@ -96,10 +123,13 @@ declare class AppleAuthProvider implements AuthProvider$1 {
96
123
  constructor(options: AppleAuthOptions);
97
124
  loadAppleSdk(): Promise<void>;
98
125
  init(): Promise<void>;
126
+ buildAuthUrl(): string;
99
127
  signIn(): Promise<void>;
100
128
  signOut(): void;
101
129
  getAccessToken(): Promise<string | null>;
102
130
  getUserInfo(): Promise<any>;
131
+ setToken(token: string): void;
132
+ setUser(user: any): void;
103
133
  }
104
134
 
105
135
  declare global {
@@ -123,6 +153,7 @@ declare class MetaAuthProvider implements AuthProvider$1 {
123
153
  private redirectUri?;
124
154
  private scope;
125
155
  private isPopup;
156
+ private lastState?;
126
157
  private onSuccess?;
127
158
  private onFail?;
128
159
  private accessToken;
@@ -130,14 +161,15 @@ declare class MetaAuthProvider implements AuthProvider$1 {
130
161
  constructor(options: MetaAuthOptions);
131
162
  loadFacebookSdk(): Promise<void>;
132
163
  init(): Promise<void>;
133
- signIn(): void;
164
+ buildAuthUrl(): string;
165
+ signIn(): Promise<void>;
134
166
  signOut(): void;
167
+ fetchUserInfo(): Promise<any>;
135
168
  getAccessToken(): Promise<string | null>;
136
169
  getUserInfo(): Promise<any>;
137
170
  setToken(token: string): void;
138
171
  setUser(user: any): void;
139
172
  }
140
- declare const FacebookAuthProvider: typeof MetaAuthProvider;
141
173
 
142
174
  declare global {
143
175
  interface Window {
@@ -146,24 +178,37 @@ declare global {
146
178
  }
147
179
  interface KakaoAuthOptions {
148
180
  javascriptKey: string;
181
+ restApiKey?: string;
149
182
  redirectUri?: string;
150
183
  scope?: string;
184
+ isPopup?: boolean;
185
+ state?: string;
151
186
  onSuccess?: (authObj: any) => void;
152
187
  onFail?: (error: any) => void;
153
188
  }
154
189
  declare class KakaoAuthProvider implements AuthProvider$1 {
155
190
  private javascriptKey;
191
+ private restApiKey?;
156
192
  private redirectUri?;
157
193
  private scope?;
194
+ private isPopup;
195
+ private state?;
196
+ private lastState?;
158
197
  private onSuccess?;
159
198
  private onFail?;
199
+ private accessToken;
200
+ private userInfo;
160
201
  constructor(options: KakaoAuthOptions);
202
+ buildAuthUrl(): string;
161
203
  loadKakaoSdk(): Promise<void>;
162
204
  init(): Promise<void>;
163
- signIn(): void;
205
+ signIn(): Promise<void>;
164
206
  signOut(): void;
207
+ fetchUserInfo(): Promise<any>;
165
208
  getAccessToken(): Promise<string | null>;
166
209
  getUserInfo(): Promise<any>;
210
+ setToken(token: string): void;
211
+ setUser(user: any): void;
167
212
  }
168
213
 
169
214
  declare global {
@@ -174,24 +219,40 @@ declare global {
174
219
  interface NaverAuthOptions {
175
220
  clientId: string;
176
221
  callbackUrl: string;
222
+ responseType?: 'code' | 'token';
177
223
  isPopup?: boolean;
224
+ state?: string;
225
+ useLegacySdk?: boolean;
178
226
  loginButtonId?: string;
179
227
  callbackHandle?: (status: boolean) => void;
228
+ onSuccess?: (response: any) => void;
229
+ onFail?: (error: any) => void;
180
230
  }
181
231
  declare class NaverAuthProvider implements AuthProvider$1 {
182
232
  private clientId;
183
233
  private callbackUrl;
234
+ private responseType;
184
235
  private isPopup;
185
- private loginButtonId;
236
+ private state?;
237
+ private lastState?;
238
+ private useLegacySdk;
239
+ private loginButtonId?;
186
240
  private callbackHandle?;
241
+ private onSuccess?;
242
+ private onFail?;
187
243
  private naverLoginInstance;
244
+ private accessToken;
245
+ private userInfo;
188
246
  constructor(options: NaverAuthOptions);
189
- loadNaverSdk(): Promise<void>;
247
+ buildAuthUrl(): string;
248
+ loadLegacySdk(): Promise<void>;
190
249
  init(): Promise<void>;
191
- signIn(): void;
250
+ signIn(): Promise<void>;
192
251
  signOut(): void;
193
252
  getAccessToken(): Promise<string | null>;
194
253
  getUserInfo(): Promise<any>;
254
+ setToken(token: string): void;
255
+ setUser(user: any): void;
195
256
  }
196
257
 
197
258
  interface LineAuthOptions {
@@ -210,6 +271,7 @@ declare class LineAuthProvider implements AuthProvider$1 {
210
271
  private callbackUrl;
211
272
  private scope;
212
273
  private state?;
274
+ private lastState?;
213
275
  private nonce?;
214
276
  private isPopup;
215
277
  private botPrompt?;
@@ -254,6 +316,7 @@ declare class GithubAuthProvider implements AuthProvider$1 {
254
316
  private scope;
255
317
  private isPopup;
256
318
  private state?;
319
+ private lastState?;
257
320
  private usePkce;
258
321
  private onSuccess?;
259
322
  private onFail?;
@@ -288,6 +351,7 @@ declare class DiscordAuthProvider implements AuthProvider$1 {
288
351
  private scope;
289
352
  private isPopup;
290
353
  private state?;
354
+ private lastState?;
291
355
  private usePkce;
292
356
  private prompt?;
293
357
  private onSuccess?;
@@ -450,6 +514,7 @@ declare class PasskeyAuthProvider implements AuthProvider$1 {
450
514
  challenge?: Uint8Array;
451
515
  userName?: string;
452
516
  userId?: string;
517
+ authenticatorAttachment?: 'platform' | 'cross-platform';
453
518
  }): Promise<any>;
454
519
  /**
455
520
  * Performs Passkey authentication (navigator.credentials.get)
@@ -465,6 +530,10 @@ declare class PasskeyAuthProvider implements AuthProvider$1 {
465
530
  * OAuth 2.0 PKCE (Proof Key for Code Exchange) utilities
466
531
  * Compatible with modern browser Web Crypto API.
467
532
  */
533
+ /**
534
+ * Generates a cryptographically random state/nonce string.
535
+ */
536
+ declare function generateRandomState(length?: number): string;
468
537
  /**
469
538
  * Generates a cryptographically random code verifier string (43~128 chars).
470
539
  */
@@ -488,16 +557,47 @@ interface BuildAuthorizeUrlOptions {
488
557
  * Builds an OAuth 2.0 authorization URL
489
558
  */
490
559
  declare function buildAuthorizeUrl(options: BuildAuthorizeUrlOptions): string;
491
- /**
492
- * Parses query params from OAuth redirect callback URL
493
- */
494
- declare function parseOAuthCallback(urlOrSearch?: string): {
560
+ interface OAuthCallbackResult {
495
561
  code?: string;
496
562
  state?: string;
497
563
  error?: string;
498
564
  error_description?: string;
499
565
  token?: string;
500
- };
566
+ access_token?: string;
567
+ id_token?: string;
568
+ token_type?: string;
569
+ expires_in?: string;
570
+ [key: string]: string | undefined;
571
+ }
572
+ /**
573
+ * Parses query and hash params from OAuth redirect callback URL or browser location
574
+ */
575
+ declare function parseOAuthCallback(urlOrSearch?: string): OAuthCallbackResult;
576
+ interface HandleOAuthCallbackOptions {
577
+ targetOrigin?: string;
578
+ closePopup?: boolean;
579
+ storageKey?: string;
580
+ urlOrSearch?: string;
581
+ }
582
+ /**
583
+ * Handles the OAuth redirect or popup callback.
584
+ * If running inside a popup (window.opener exists), communicates the payload back to the opener via postMessage.
585
+ * Automatically parses both query string and hash fragment.
586
+ */
587
+ declare function handleOAuthCallback(options?: HandleOAuthCallbackOptions): OAuthCallbackResult;
588
+ /**
589
+ * Opens a centered popup window for OAuth authorization.
590
+ */
591
+ declare function openOAuthPopup(url: string, title?: string, width?: number, height?: number): Window | null;
592
+ interface WaitForPopupOptions {
593
+ timeoutMs?: number;
594
+ expectedOrigin?: string;
595
+ expectedState?: string;
596
+ }
597
+ /**
598
+ * Waits for a message from an OAuth popup window or detects if it was closed.
599
+ */
600
+ declare function waitForOAuthPopupMessage(popup: Window | null, timeoutMsOrOptions?: number | WaitForPopupOptions): Promise<OAuthCallbackResult>;
501
601
 
502
602
  declare const identityProviders: {
503
603
  world: typeof WorldAuthProvider;
@@ -1055,6 +1155,7 @@ declare function clearStoreSession(): void;
1055
1155
 
1056
1156
  interface AuthCoreProps {
1057
1157
  providerType?: CoreProviderType;
1158
+ serviceType?: AuthServiceType;
1058
1159
  secret?: string;
1059
1160
  storage?: StorageType;
1060
1161
  storagePrefix?: string;
@@ -1064,7 +1165,7 @@ declare class AuthCore {
1064
1165
  private button;
1065
1166
  private serviceInstance;
1066
1167
  lifecycle: AuthLifecycleManager;
1067
- constructor({ providerType, secret, storage, storagePrefix, }?: AuthCoreProps);
1168
+ constructor({ providerType, serviceType: explicitServiceType, secret, storage, storagePrefix, }?: AuthCoreProps);
1068
1169
  getService(): AuthBaseService | JwtService;
1069
1170
  getProvider(): typeof GoogleAuthProvider | typeof AppleAuthProvider | typeof MetaAuthProvider | typeof KakaoAuthProvider | typeof NaverAuthProvider | typeof LineAuthProvider | typeof GithubAuthProvider | typeof DiscordAuthProvider | typeof Web3AuthProvider | typeof WorldAuthProvider | typeof PasskeyAuthProvider | null;
1070
1171
  getButton(): LoginButton | null;
@@ -1748,8 +1849,8 @@ declare namespace index {
1748
1849
  }
1749
1850
 
1750
1851
  /**
1751
- * React Type-Safe Wrapper Component for ISA-AUTH Buttons
1752
- * Provides 100% TypeScript Props & Event IntelliSense
1852
+ * React Type-Safe Wrapper Component & Hook for ISA-AUTH
1853
+ * Compatible with Next.js, Vite, CRA, Remix, and standard React apps.
1753
1854
  */
1754
1855
 
1755
1856
  interface IsaAuthButtonProps {
@@ -1763,9 +1864,25 @@ interface IsaAuthButtonProps {
1763
1864
  children?: any;
1764
1865
  }
1765
1866
  /**
1766
- * Creates a strongly typed React Component from an IsaAuth instance
1867
+ * Creates a strongly typed React Component from an IsaAuth instance.
1868
+ * Accepts optional `reactInstance` for environments where `React` is not attached to window.
1869
+ */
1870
+ declare function createReactAuthButton(authInstance?: IsaAuth, reactInstance?: any): (props: IsaAuthButtonProps) => any;
1871
+ /**
1872
+ * React hook for reactive ISA-AUTH state subscription.
1873
+ * Accepts an IsaAuth instance and optional reactInstance.
1767
1874
  */
1768
- declare function createReactAuthButton(authInstance: IsaAuth): (props: IsaAuthButtonProps) => any;
1875
+ declare function useIsaAuth(auth: IsaAuth, reactInstance?: any): {
1876
+ isAuthenticated: any;
1877
+ user: any;
1878
+ token: any;
1879
+ signIn: (provider?: CoreProviderType) => Promise<any>;
1880
+ signOut: () => void;
1881
+ getAccessToken: () => string;
1882
+ getUserInfo: () => any;
1883
+ can: (permission: string | string[], matchAll?: boolean) => boolean;
1884
+ is: (role: string | string[], matchAll?: boolean) => boolean;
1885
+ };
1769
1886
 
1770
1887
  interface ProviderOptionConfig {
1771
1888
  clientId?: string;
@@ -1813,6 +1930,12 @@ declare class IsaAuth {
1813
1930
  updateAuthInfo<T = any>(partial: Partial<T>): T;
1814
1931
  signIn(provider?: CoreProviderType): Promise<any>;
1815
1932
  signOut(): void;
1933
+ /**
1934
+ * Handles incoming OAuth redirect or popup callbacks.
1935
+ * If running inside an authentication popup, communicates payload back to opener and closes popup.
1936
+ */
1937
+ static handleCallback(options?: HandleOAuthCallbackOptions): OAuthCallbackResult;
1938
+ handleCallback(options?: HandleOAuthCallbackOptions): OAuthCallbackResult;
1816
1939
  refresh(refreshFn: () => Promise<string>): Promise<string>;
1817
1940
  /**
1818
1941
  * Starts automatic background token refresh prior to expiration
@@ -1890,6 +2013,7 @@ declare class IsaAuth {
1890
2013
  createAxios(axiosModuleOrInstance: any, options?: Partial<AuthHttpOptions>): any;
1891
2014
  createTokenExchange(tokenEndpoint: string, options?: any): HttpTokenExchangeAdapter;
1892
2015
  subscribe(callback: (isAuthenticated: boolean) => void): void | (() => void);
2016
+ watchAuthState(callback: (isAuthenticated: boolean) => void): void | (() => void);
1893
2017
  }
1894
2018
 
1895
- export { AppleAuthProvider, AuthBaseService, type AuthContext, AuthCore, type AuthFetchOptions, type AuthGuardOptions, type AuthHttpOptions, AuthProvider, type AutoRefreshOptions, CookieSessionStorageAdapter, DiscordAuthProvider, FacebookAuthProvider, GithubAuthProvider, GoogleAuthProvider, type GuardFailureReason, type GuardResult, HttpTokenExchangeAdapter, IsaAuth, type IsaAuthButtonAttributes, type IsaAuthButtonProps, type IsaAuthConfig, JwtService, KakaoAuthProvider, LineAuthProvider, LocalStorageAdapter, type MatchMode, MemoryStorageAdapter, MetaAuthProvider, NaverAuthProvider, type PasskeyAssertionResult, PasskeyAuthProvider, type ProviderCategory, type ProviderOptionConfig, type RoleHierarchyMap, SessionStorageAdapter, type StorageConfig, type StorageType, type TokenExchangeAdapter, type TokenExchangeResult, Web3AuthProvider, WorldAuthProvider, type WorldIDProofResult, type WorldVerificationLevel, applyAuthInterceptor, batch, buildAuthorizeUrl, checkPermission, checkRole, clearStoreSession, configureStorage, createAuthAxios, createAuthFetch, createAuthGuard, createNavigationGuard, createReactAuthButton, decodeToken, IsaAuth as default, developerProviders, evaluateGuard, generateCodeChallenge, generateCodeVerifier, getAccessToken, getAuthInfo, getAuthState, getProviderCategory, getProvidersByCategory, getRefreshToken, getStorageAdapter, getTokenFromHeader, getTokenPayload, getTokenTimeRemaining, identityProviders, isExpiredToken, matchPermissionRule, parseOAuthCallback, index as renderers, resolveInheritedRoles, setRefreshToken, socialProviders, subscribeSelector, updateAuthInfo, web3Providers };
2019
+ export { AppleAuthProvider, AuthBaseService, type AuthContext, AuthCore, type AuthFetchOptions, type AuthGuardOptions, type AuthHttpOptions, AuthProvider, type AutoRefreshOptions, CookieSessionStorageAdapter, DiscordAuthProvider, MetaAuthProvider as FacebookAuthProvider, GithubAuthProvider, GoogleAuthProvider, type GuardFailureReason, type GuardResult, type HandleOAuthCallbackOptions, HttpTokenExchangeAdapter, IsaAuth, type IsaAuthButtonAttributes, type IsaAuthButtonProps, type IsaAuthConfig, JwtService, KakaoAuthProvider, LineAuthProvider, LocalStorageAdapter, type MatchMode, MemoryStorageAdapter, MetaAuthProvider, NaverAuthProvider, type OAuthCallbackResult, type PasskeyAssertionResult, PasskeyAuthProvider, type ProviderCategory, type ProviderOptionConfig, type RoleHierarchyMap, SessionStorageAdapter, type StorageConfig, type StorageType, type TokenExchangeAdapter, type TokenExchangeResult, type WaitForPopupOptions, Web3AuthProvider, WorldAuthProvider, type WorldIDProofResult, type WorldVerificationLevel, applyAuthInterceptor, batch, buildAuthorizeUrl, checkPermission, checkRole, clearStoreSession, configureStorage, createAuthAxios, createAuthFetch, createAuthGuard, createNavigationGuard, createReactAuthButton, decodeToken, IsaAuth as default, developerProviders, evaluateGuard, generateCodeChallenge, generateCodeVerifier, generateRandomState, getAccessToken, getAuthInfo, getAuthState, getProviderCategory, getProvidersByCategory, getRefreshToken, getStorageAdapter, getTokenFromHeader, getTokenPayload, getTokenTimeRemaining, handleOAuthCallback, identityProviders, isExpiredToken, matchPermissionRule, openOAuthPopup, parseOAuthCallback, index as renderers, resolveInheritedRoles, setRefreshToken, socialProviders, subscribeSelector, updateAuthInfo, useIsaAuth, waitForOAuthPopupMessage, web3Providers };