@nauth-toolkit/client 0.1.49 → 0.1.53

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.
@@ -1,2030 +0,0 @@
1
- import { InjectionToken, Injector, ModuleWithProviders } from '@angular/core';
2
- import * as rxjs from 'rxjs';
3
- import { Observable } from 'rxjs';
4
- import * as _angular_common_http from '@angular/common/http';
5
- import { HttpInterceptorFn, HttpRequest as HttpRequest$1, HttpHandlerFn } from '@angular/common/http';
6
- import { CanActivateFn, Router, UrlTree } from '@angular/router';
7
-
8
- /**
9
- * Full user profile returned from profile endpoints.
10
- */
11
- interface AuthUser {
12
- sub: string;
13
- email: string;
14
- username?: string | null;
15
- firstName?: string | null;
16
- lastName?: string | null;
17
- phone?: string | null;
18
- isEmailVerified: boolean;
19
- isPhoneVerified: boolean;
20
- isActive?: boolean;
21
- mfaEnabled?: boolean;
22
- socialProviders?: string[] | null;
23
- hasPasswordHash: boolean;
24
- /**
25
- * Authentication method used to create the current session.
26
- *
27
- * This is session-scoped (how the user logged in this time), not an account capability.
28
- * Use `hasPasswordHash` and `socialProviders` to determine what login methods the account supports.
29
- */
30
- sessionAuthMethod?: string | null;
31
- createdAt?: string | Date;
32
- updatedAt?: string | Date;
33
- }
34
- /**
35
- * Profile update request.
36
- */
37
- interface UpdateProfileRequest {
38
- firstName?: string;
39
- lastName?: string;
40
- email?: string;
41
- phone?: string;
42
- }
43
- /**
44
- * Forgot password response payload.
45
- */
46
- interface ForgotPasswordResponse {
47
- success: boolean;
48
- destination?: string;
49
- deliveryMedium?: 'email' | 'sms';
50
- expiresIn?: number;
51
- }
52
- /**
53
- * Confirm forgot password response payload.
54
- */
55
- interface ConfirmForgotPasswordResponse {
56
- success: boolean;
57
- mustChangePassword: boolean;
58
- }
59
-
60
- /**
61
- * Standardized error codes mirroring backend AuthErrorCode.
62
- */
63
- declare enum NAuthErrorCode {
64
- AUTH_INVALID_CREDENTIALS = "AUTH_INVALID_CREDENTIALS",
65
- AUTH_ACCOUNT_LOCKED = "AUTH_ACCOUNT_LOCKED",
66
- AUTH_ACCOUNT_INACTIVE = "AUTH_ACCOUNT_INACTIVE",
67
- AUTH_TOKEN_EXPIRED = "AUTH_TOKEN_EXPIRED",
68
- AUTH_TOKEN_INVALID = "AUTH_TOKEN_INVALID",
69
- AUTH_BEARER_NOT_ALLOWED = "AUTH_BEARER_NOT_ALLOWED",
70
- AUTH_COOKIES_NOT_ALLOWED = "AUTH_COOKIES_NOT_ALLOWED",
71
- AUTH_CSRF_TOKEN_INVALID = "AUTH_CSRF_TOKEN_INVALID",
72
- AUTH_CSRF_TOKEN_MISSING = "AUTH_CSRF_TOKEN_MISSING",
73
- AUTH_TOKEN_REUSE_DETECTED = "AUTH_TOKEN_REUSE_DETECTED",
74
- AUTH_SESSION_NOT_FOUND = "AUTH_SESSION_NOT_FOUND",
75
- AUTH_SESSION_EXPIRED = "AUTH_SESSION_EXPIRED",
76
- SIGNUP_DISABLED = "SIGNUP_DISABLED",
77
- SIGNUP_EMAIL_EXISTS = "SIGNUP_EMAIL_EXISTS",
78
- SIGNUP_USERNAME_EXISTS = "SIGNUP_USERNAME_EXISTS",
79
- SIGNUP_PHONE_EXISTS = "SIGNUP_PHONE_EXISTS",
80
- SIGNUP_WEAK_PASSWORD = "SIGNUP_WEAK_PASSWORD",
81
- SIGNUP_PHONE_REQUIRED = "SIGNUP_PHONE_REQUIRED",
82
- SIGNUP_NOT_ALLOWED = "SIGNUP_NOT_ALLOWED",
83
- VERIFY_CODE_INVALID = "VERIFY_CODE_INVALID",
84
- VERIFY_CODE_EXPIRED = "VERIFY_CODE_EXPIRED",
85
- VERIFY_TOO_MANY_ATTEMPTS = "VERIFY_TOO_MANY_ATTEMPTS",
86
- VERIFY_ALREADY_VERIFIED = "VERIFY_ALREADY_VERIFIED",
87
- MFA_SETUP_REQUIRED = "MFA_SETUP_REQUIRED",
88
- RATE_LIMIT_SMS = "RATE_LIMIT_SMS",
89
- RATE_LIMIT_EMAIL = "RATE_LIMIT_EMAIL",
90
- RATE_LIMIT_LOGIN = "RATE_LIMIT_LOGIN",
91
- RATE_LIMIT_RESEND = "RATE_LIMIT_RESEND",
92
- SOCIAL_TOKEN_INVALID = "SOCIAL_TOKEN_INVALID",
93
- SOCIAL_ACCOUNT_LINKED = "SOCIAL_ACCOUNT_LINKED",
94
- SOCIAL_CONFIG_MISSING = "SOCIAL_CONFIG_MISSING",
95
- SOCIAL_EMAIL_REQUIRED = "SOCIAL_EMAIL_REQUIRED",
96
- SOCIAL_ACCOUNT_NOT_FOUND = "SOCIAL_ACCOUNT_NOT_FOUND",
97
- CHALLENGE_EXPIRED = "CHALLENGE_EXPIRED",
98
- CHALLENGE_INVALID = "CHALLENGE_INVALID",
99
- CHALLENGE_TYPE_MISMATCH = "CHALLENGE_TYPE_MISMATCH",
100
- CHALLENGE_MAX_ATTEMPTS = "CHALLENGE_MAX_ATTEMPTS",
101
- CHALLENGE_ALREADY_COMPLETED = "CHALLENGE_ALREADY_COMPLETED",
102
- VALIDATION_FAILED = "VALIDATION_FAILED",
103
- VALIDATION_INVALID_PHONE = "VALIDATION_INVALID_PHONE",
104
- VALIDATION_INVALID_EMAIL = "VALIDATION_INVALID_EMAIL",
105
- VALIDATION_INVALID_PASSWORD = "VALIDATION_INVALID_PASSWORD",
106
- PASSWORD_INCORRECT = "PASSWORD_INCORRECT",
107
- PASSWORD_REUSED = "PASSWORD_REUSED",
108
- PASSWORD_CHANGE_NOT_ALLOWED = "PASSWORD_CHANGE_NOT_ALLOWED",
109
- WEAK_PASSWORD = "SIGNUP_WEAK_PASSWORD",
110
- PASSWORD_RESET_CODE_INVALID = "PASSWORD_RESET_CODE_INVALID",
111
- PASSWORD_RESET_CODE_EXPIRED = "PASSWORD_RESET_CODE_EXPIRED",
112
- PASSWORD_RESET_MAX_ATTEMPTS = "PASSWORD_RESET_MAX_ATTEMPTS",
113
- RATE_LIMIT_PASSWORD_RESET = "RATE_LIMIT_PASSWORD_RESET",
114
- SIGNIN_BLOCKED_HIGH_RISK = "SIGNIN_BLOCKED_HIGH_RISK",
115
- RESOURCE_NOT_FOUND = "RESOURCE_NOT_FOUND",
116
- FORBIDDEN = "FORBIDDEN",
117
- INTERNAL_ERROR = "INTERNAL_ERROR",
118
- SERVICE_UNAVAILABLE = "SERVICE_UNAVAILABLE"
119
- }
120
- /**
121
- * Structured client error.
122
- */
123
- interface NAuthError {
124
- code: NAuthErrorCode;
125
- message: string;
126
- details?: Record<string, unknown>;
127
- timestamp?: string;
128
- statusCode?: number;
129
- }
130
-
131
- /**
132
- * Storage adapter interface used by the client SDK.
133
- */
134
- interface NAuthStorageAdapter {
135
- /**
136
- * Retrieve a value by key.
137
- */
138
- getItem(key: string): Promise<string | null>;
139
- /**
140
- * Persist a value.
141
- */
142
- setItem(key: string, value: string): Promise<void>;
143
- /**
144
- * Remove a stored value.
145
- */
146
- removeItem(key: string): Promise<void>;
147
- /**
148
- * Clear all stored values.
149
- */
150
- clear(): Promise<void>;
151
- }
152
-
153
- /**
154
- * HTTP request configuration.
155
- *
156
- * Platform-agnostic request format that can be implemented by any HTTP client.
157
- */
158
- interface HttpRequest {
159
- /**
160
- * HTTP method
161
- */
162
- method: 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH';
163
- /**
164
- * Full URL (already resolved with baseUrl)
165
- */
166
- url: string;
167
- /**
168
- * Request headers
169
- */
170
- headers?: Record<string, string>;
171
- /**
172
- * Request body (will be JSON stringified by adapter)
173
- */
174
- body?: unknown;
175
- /**
176
- * Credentials mode for cookies
177
- * - 'include': Send cookies (for cookies mode)
178
- * - 'omit': Don't send cookies (for JSON mode)
179
- */
180
- credentials?: 'include' | 'omit' | 'same-origin';
181
- /**
182
- * Abort signal for request cancellation
183
- */
184
- signal?: AbortSignal;
185
- }
186
- /**
187
- * HTTP response returned by adapter.
188
- */
189
- interface HttpResponse<T> {
190
- /**
191
- * Response data (already parsed)
192
- */
193
- data: T;
194
- /**
195
- * HTTP status code
196
- */
197
- status: number;
198
- /**
199
- * Response headers
200
- */
201
- headers: Record<string, string>;
202
- }
203
- /**
204
- * Platform-agnostic HTTP adapter interface.
205
- *
206
- * Implementations:
207
- * - FetchAdapter: For vanilla JS, Node.js (uses native fetch)
208
- * - AngularHttpAdapter: For Angular (uses HttpClient)
209
- * - AxiosAdapter: For React/Vue (uses Axios)
210
- *
211
- * @example
212
- * ```typescript
213
- * class MyAdapter implements HttpAdapter {
214
- * async request<T>(config: HttpRequest): Promise<HttpResponse<T>> {
215
- * // Use any HTTP client
216
- * const response = await myHttpClient.request(config);
217
- * return { data: response.data, status: response.status, headers: {} };
218
- * }
219
- * }
220
- * ```
221
- */
222
- interface HttpAdapter {
223
- /**
224
- * Execute an HTTP request.
225
- *
226
- * @param config - Request configuration
227
- * @returns Response with data, status, and headers
228
- * @throws Error if request fails (adapter should throw descriptive errors)
229
- */
230
- request<T>(config: HttpRequest): Promise<HttpResponse<T>>;
231
- }
232
-
233
- /**
234
- * Token delivery mode for the frontend SDK.
235
- *
236
- * - `'cookies'` - For web applications. Tokens sent as httpOnly cookies by backend.
237
- * Uses `withCredentials`, CSRF tokens, no Authorization header.
238
- *
239
- * - `'json'` - For mobile/native apps (Capacitor, React Native). Tokens returned
240
- * in response body, stored locally, sent via Authorization header.
241
- *
242
- * Note: "Hybrid" is a backend deployment pattern (supporting both web and mobile
243
- * via separate endpoints), not a frontend mode. The frontend chooses ONE mode
244
- * based on whether it's a web or mobile build.
245
- */
246
- type TokenDeliveryMode = 'json' | 'cookies';
247
- /**
248
- * Endpoint paths for the client SDK.
249
- */
250
- interface NAuthEndpoints {
251
- login: string;
252
- signup: string;
253
- logout: string;
254
- logoutAll: string;
255
- refresh: string;
256
- respondChallenge: string;
257
- resendCode: string;
258
- getSetupData: string;
259
- getChallengeData: string;
260
- profile: string;
261
- changePassword: string;
262
- requestPasswordChange: string;
263
- forgotPassword: string;
264
- confirmForgotPassword: string;
265
- mfaStatus: string;
266
- mfaDevices: string;
267
- mfaSetupData: string;
268
- mfaVerifySetup: string;
269
- mfaRemove: string;
270
- mfaPreferred: string;
271
- mfaBackupCodes: string;
272
- mfaExemption: string;
273
- socialLinked: string;
274
- socialLink: string;
275
- socialUnlink: string;
276
- socialVerify: string;
277
- socialRedirectStart: string;
278
- socialExchange: string;
279
- trustDevice: string;
280
- isTrustedDevice: string;
281
- auditHistory: string;
282
- updateProfile: string;
283
- }
284
- /**
285
- * Client configuration.
286
- */
287
- interface NAuthClientConfig {
288
- /**
289
- * Base URL for authentication API.
290
- *
291
- * For web apps using cookies: `'https://api.example.com/auth'`
292
- * For mobile apps using JSON: `'https://api.example.com/mobile/auth'`
293
- *
294
- * When backend uses hybrid deployment, mobile apps should use a different
295
- * base URL that points to the JSON-based mobile auth endpoints.
296
- */
297
- baseUrl: string;
298
- /**
299
- * How tokens are delivered between client and server.
300
- *
301
- * - `'cookies'` - For web apps. Backend sets httpOnly cookies.
302
- * - `'json'` - For mobile apps. Tokens in response body, stored locally.
303
- */
304
- tokenDelivery: TokenDeliveryMode;
305
- /** Custom storage adapter. Defaults to localStorage (web) or memory (SSR). */
306
- storage?: NAuthStorageAdapter;
307
- /**
308
- * CSRF configuration (required for cookies mode).
309
- * Default cookie name: 'csrf_token', header name: 'x-csrf-token'
310
- */
311
- csrf?: {
312
- cookieName?: string;
313
- headerName?: string;
314
- };
315
- /** Custom endpoint paths (merged with defaults). */
316
- endpoints?: Partial<NAuthEndpoints>;
317
- /** Device trust configuration for "remember this device" feature. */
318
- deviceTrust?: {
319
- headerName?: string;
320
- storageKey?: string;
321
- };
322
- /** Additional headers to include in all requests. */
323
- headers?: Record<string, string>;
324
- /** Request timeout in milliseconds. Default: 30000 */
325
- timeout?: number;
326
- /**
327
- * Redirect URLs for various authentication scenarios.
328
- * Used by guards and interceptors to handle routing in a platform-agnostic way.
329
- */
330
- redirects?: {
331
- /**
332
- * URL to redirect to after successful authentication (login, signup, or OAuth).
333
- * @default '/'
334
- */
335
- success?: string;
336
- /**
337
- * URL to redirect to when session expires (refresh fails with 401).
338
- * @default '/login'
339
- */
340
- sessionExpired?: string;
341
- /**
342
- * URL to redirect to when OAuth authentication fails.
343
- * @default '/login'
344
- */
345
- oauthError?: string;
346
- /**
347
- * Base URL for challenge routes (email verification, MFA, etc.).
348
- * The challenge type will be appended (e.g., '/auth/challenge/verify-email').
349
- * @default '/auth/challenge'
350
- */
351
- challengeBase?: string;
352
- };
353
- /**
354
- * Called when session expires (refresh fails with 401).
355
- */
356
- onSessionExpired?: () => void;
357
- /** Called after successful token refresh. */
358
- onTokenRefresh?: () => void;
359
- /** Called when authentication state changes (login/logout). */
360
- onAuthStateChange?: (user: AuthUser | null) => void;
361
- /** Called on authentication errors. */
362
- onError?: (error: NAuthError) => void;
363
- /** Enable debug logging. */
364
- debug?: boolean;
365
- /**
366
- * HTTP adapter for making requests.
367
- *
368
- * - **Auto-provided in Angular**: Uses HttpClient (works with interceptors)
369
- * - **Manual setup in React/Vue**: Provide AxiosAdapter or custom adapter
370
- * - **Defaults to FetchAdapter**: If not provided, uses native fetch
371
- *
372
- * @example
373
- * ```typescript
374
- * // Angular (automatic)
375
- * // AuthService auto-injects AngularHttpAdapter
376
- *
377
- * // React with Axios
378
- * const client = new NAuthClient({
379
- * httpAdapter: new AxiosAdapter(axiosInstance),
380
- * });
381
- *
382
- * // Vanilla JS (auto-defaults to fetch)
383
- * const client = new NAuthClient({
384
- * // httpAdapter auto-defaults to FetchAdapter
385
- * });
386
- * ```
387
- */
388
- httpAdapter?: HttpAdapter;
389
- }
390
-
391
- /**
392
- * Injection token for providing NAuthClientConfig in Angular apps.
393
- */
394
- declare const NAUTH_CLIENT_CONFIG: InjectionToken<NAuthClientConfig>;
395
-
396
- /**
397
- * MFA device method type (methods that require device setup).
398
- * Excludes 'backup' as it's not a device method.
399
- */
400
- type MFADeviceMethod = 'sms' | 'email' | 'totp' | 'passkey';
401
- /**
402
- * All MFA methods including backup codes (for verification).
403
- */
404
- type MFAMethod = MFADeviceMethod | 'backup';
405
- /**
406
- * MFA challenge method subset (for challenge-data retrieval).
407
- */
408
- type MFAChallengeMethod = 'passkey' | 'sms' | 'email' | 'totp' | 'backup';
409
- /**
410
- * MFA status for authenticated user.
411
- */
412
- interface MFAStatus {
413
- enabled: boolean;
414
- required: boolean;
415
- methods: MFADeviceMethod[];
416
- availableMethods: MFAMethod[];
417
- hasBackupCodes: boolean;
418
- preferredMethod?: MFADeviceMethod;
419
- mfaExempt: boolean;
420
- mfaExemptReason: string | null;
421
- mfaExemptGrantedAt: string | Date | null;
422
- }
423
- /**
424
- * MFA device information.
425
- */
426
- interface MFADevice {
427
- id: number;
428
- type: MFADeviceMethod;
429
- name: string;
430
- isPrimary: boolean;
431
- isActive: boolean;
432
- createdAt: string | Date;
433
- }
434
- /**
435
- * Response from getSetupData API call.
436
- * Contains provider-specific MFA setup information.
437
- */
438
- interface GetSetupDataResponse {
439
- setupData: Record<string, unknown>;
440
- }
441
- /**
442
- * Response from getChallengeData API call.
443
- * Contains challenge-specific data (e.g., passkey options).
444
- */
445
- interface GetChallengeDataResponse {
446
- challengeData: Record<string, unknown>;
447
- }
448
-
449
- /**
450
- * Authentication challenge types returned by the backend.
451
- */
452
- declare enum AuthChallenge {
453
- VERIFY_EMAIL = "VERIFY_EMAIL",
454
- VERIFY_PHONE = "VERIFY_PHONE",
455
- MFA_REQUIRED = "MFA_REQUIRED",
456
- MFA_SETUP_REQUIRED = "MFA_SETUP_REQUIRED",
457
- FORCE_CHANGE_PASSWORD = "FORCE_CHANGE_PASSWORD"
458
- }
459
-
460
- interface AuthResponse {
461
- user?: AuthUserSummary;
462
- accessToken?: string;
463
- refreshToken?: string;
464
- accessTokenExpiresAt?: number;
465
- refreshTokenExpiresAt?: number;
466
- /**
467
- * Authentication method used to create the current session.
468
- *
469
- * Examples:
470
- * - `password`
471
- * - `google`
472
- * - `apple`
473
- * - `facebook`
474
- */
475
- authMethod?: string;
476
- trusted?: boolean;
477
- deviceToken?: string;
478
- challengeName?: AuthChallenge;
479
- session?: string;
480
- challengeParameters?: Record<string, unknown>;
481
- userSub?: string;
482
- }
483
- /**
484
- * Minimal user information returned inside auth responses.
485
- */
486
- interface AuthUserSummary {
487
- sub: string;
488
- email: string;
489
- firstName?: string | null;
490
- lastName?: string | null;
491
- phone?: string | null;
492
- isEmailVerified: boolean;
493
- isPhoneVerified?: boolean;
494
- socialProviders?: string[] | null;
495
- hasPasswordHash?: boolean;
496
- }
497
- /**
498
- * Token response returned by refresh endpoint.
499
- */
500
- interface TokenResponse {
501
- accessToken: string;
502
- refreshToken: string;
503
- accessTokenExpiresAt: number;
504
- refreshTokenExpiresAt: number;
505
- }
506
- /**
507
- * Signup request payload.
508
- */
509
- interface SignupRequest {
510
- email: string;
511
- password: string;
512
- firstName?: string;
513
- lastName?: string;
514
- phone?: string;
515
- metadata?: Record<string, unknown>;
516
- }
517
- /**
518
- * MFA setup data request payload during challenge flows.
519
- */
520
- interface GetSetupDataRequest {
521
- session: string;
522
- method: MFAMethod;
523
- }
524
- /**
525
- * Challenge data request payload (e.g., passkey options).
526
- */
527
- interface GetChallengeDataRequest {
528
- session: string;
529
- method: MFAChallengeMethod;
530
- }
531
- /**
532
- * Unified challenge response discriminated union.
533
- */
534
- type ChallengeResponse = VerifyEmailResponse | VerifyPhoneCollectResponse | VerifyPhoneCodeResponse | MFACodeResponse | MFAPasskeyResponse | MFASetupResponse | ForceChangePasswordResponse;
535
- /**
536
- * Base challenge response shape.
537
- */
538
- interface BaseChallengeResponse {
539
- session: string;
540
- }
541
- interface VerifyEmailResponse extends BaseChallengeResponse {
542
- type: AuthChallenge.VERIFY_EMAIL;
543
- code: string;
544
- }
545
- interface VerifyPhoneCollectResponse extends BaseChallengeResponse {
546
- type: AuthChallenge.VERIFY_PHONE;
547
- phone: string;
548
- }
549
- interface VerifyPhoneCodeResponse extends BaseChallengeResponse {
550
- type: AuthChallenge.VERIFY_PHONE;
551
- code: string;
552
- }
553
- interface MFACodeResponse extends BaseChallengeResponse {
554
- type: AuthChallenge.MFA_REQUIRED;
555
- method: MFAMethod;
556
- code: string;
557
- }
558
- interface MFAPasskeyResponse extends BaseChallengeResponse {
559
- type: AuthChallenge.MFA_REQUIRED;
560
- method: 'passkey';
561
- credential: Record<string, unknown>;
562
- }
563
- interface MFASetupResponse extends BaseChallengeResponse {
564
- type: AuthChallenge.MFA_SETUP_REQUIRED;
565
- method: MFAMethod;
566
- setupData: Record<string, unknown>;
567
- }
568
- interface ForceChangePasswordResponse extends BaseChallengeResponse {
569
- type: AuthChallenge.FORCE_CHANGE_PASSWORD;
570
- newPassword: string;
571
- }
572
-
573
- /**
574
- * Client-side error wrapper for SDK operations.
575
- *
576
- * Mirrors the backend NAuthException structure for consistent error handling.
577
- *
578
- * @example
579
- * ```typescript
580
- * try {
581
- * await client.login({ identifier: 'user@example.com', password: 'wrong' });
582
- * } catch (error) {
583
- * if (error instanceof NAuthClientError) {
584
- * console.log(error.code); // 'AUTH_INVALID_CREDENTIALS'
585
- * console.log(error.message); // 'Invalid credentials'
586
- * console.log(error.timestamp); // '2025-12-06T...'
587
- *
588
- * // Check specific error code
589
- * if (error.isCode(NAuthErrorCode.RATE_LIMIT_LOGIN)) {
590
- * const retryAfter = error.details?.retryAfter as number;
591
- * console.log(`Rate limited. Retry in ${retryAfter}s`);
592
- * }
593
- * }
594
- * }
595
- * ```
596
- */
597
- declare class NAuthClientError extends Error implements NAuthError {
598
- readonly code: NAuthErrorCode;
599
- readonly details?: Record<string, unknown>;
600
- readonly statusCode?: number;
601
- readonly timestamp: string;
602
- readonly isNetworkError: boolean;
603
- /**
604
- * Create a new client error.
605
- *
606
- * @param code - Error code from NAuthErrorCode enum
607
- * @param message - Human-readable error message
608
- * @param options - Optional metadata including details, statusCode, timestamp, and network error flag
609
- */
610
- constructor(code: NAuthErrorCode, message: string, options?: {
611
- details?: Record<string, unknown>;
612
- statusCode?: number;
613
- timestamp?: string;
614
- isNetworkError?: boolean;
615
- });
616
- /**
617
- * Check if error matches a specific error code.
618
- *
619
- * @param code - Error code to check against
620
- * @returns True if the error code matches
621
- *
622
- * @example
623
- * ```typescript
624
- * if (error.isCode(NAuthErrorCode.RATE_LIMIT_SMS)) {
625
- * // Handle SMS rate limit
626
- * }
627
- * ```
628
- */
629
- isCode(code: NAuthErrorCode): boolean;
630
- /**
631
- * Get error details/metadata.
632
- *
633
- * @returns Error details object or undefined
634
- *
635
- * @example
636
- * ```typescript
637
- * const details = error.getDetails();
638
- * if (details?.retryAfter) {
639
- * console.log(`Retry after ${details.retryAfter} seconds`);
640
- * }
641
- * ```
642
- */
643
- getDetails(): Record<string, unknown> | undefined;
644
- /**
645
- * Get the error code.
646
- *
647
- * @returns The error code enum value
648
- */
649
- getCode(): NAuthErrorCode;
650
- /**
651
- * Serialize error to JSON object.
652
- *
653
- * @returns Plain object representation
654
- *
655
- * @example
656
- * ```typescript
657
- * const errorJson = error.toJSON();
658
- * // { code: 'AUTH_INVALID_CREDENTIALS', message: '...', timestamp: '...', details: {...} }
659
- * ```
660
- */
661
- toJSON(): {
662
- code: string;
663
- message: string;
664
- timestamp: string;
665
- details?: Record<string, unknown>;
666
- statusCode?: number;
667
- };
668
- }
669
-
670
- /**
671
- * Authentication event types emitted by NAuthClient
672
- *
673
- * Events are emitted throughout the authentication lifecycle,
674
- * allowing applications to react to auth state changes.
675
- */
676
- type AuthEventType = 'auth:login' | 'auth:signup' | 'auth:success' | 'auth:challenge' | 'auth:error' | 'auth:logout' | 'auth:refresh' | 'oauth:started' | 'oauth:callback' | 'oauth:completed' | 'oauth:error';
677
- /**
678
- * Discriminated union of all authentication events with type-safe payloads
679
- *
680
- * Each event has a specific payload type for better type safety.
681
- */
682
- type AuthEvent = AuthLoginEvent | AuthSignupEvent | AuthSuccessEvent | AuthChallengeEvent | AuthErrorEvent | AuthLogoutEvent | AuthRefreshEvent | OAuthStartedEvent | OAuthCallbackEvent | OAuthCompletedEvent | OAuthErrorEvent;
683
- /**
684
- * Login initiated event
685
- */
686
- interface AuthLoginEvent {
687
- type: 'auth:login';
688
- data: {
689
- identifier: string;
690
- };
691
- timestamp: number;
692
- }
693
- /**
694
- * Signup initiated event
695
- */
696
- interface AuthSignupEvent {
697
- type: 'auth:signup';
698
- data: {
699
- email: string;
700
- };
701
- timestamp: number;
702
- }
703
- /**
704
- * Successful authentication event
705
- */
706
- interface AuthSuccessEvent {
707
- type: 'auth:success';
708
- data: AuthResponse;
709
- timestamp: number;
710
- }
711
- /**
712
- * Challenge required event
713
- */
714
- interface AuthChallengeEvent {
715
- type: 'auth:challenge';
716
- data: AuthResponse;
717
- timestamp: number;
718
- }
719
- /**
720
- * Authentication error event
721
- */
722
- interface AuthErrorEvent {
723
- type: 'auth:error';
724
- data: NAuthClientError;
725
- timestamp: number;
726
- }
727
- /**
728
- * User logged out event
729
- */
730
- interface AuthLogoutEvent {
731
- type: 'auth:logout';
732
- data: {
733
- forgetDevice?: boolean;
734
- global?: boolean;
735
- };
736
- timestamp: number;
737
- }
738
- /**
739
- * Token refreshed event
740
- */
741
- interface AuthRefreshEvent {
742
- type: 'auth:refresh';
743
- data: {
744
- success: boolean;
745
- };
746
- timestamp: number;
747
- }
748
- /**
749
- * OAuth flow started event
750
- */
751
- interface OAuthStartedEvent {
752
- type: 'oauth:started';
753
- data: {
754
- provider: string;
755
- };
756
- timestamp: number;
757
- }
758
- /**
759
- * OAuth callback received event
760
- */
761
- interface OAuthCallbackEvent {
762
- type: 'oauth:callback';
763
- data: {
764
- provider: string;
765
- };
766
- timestamp: number;
767
- }
768
- /**
769
- * OAuth flow completed event
770
- */
771
- interface OAuthCompletedEvent {
772
- type: 'oauth:completed';
773
- data: AuthResponse;
774
- timestamp: number;
775
- }
776
- /**
777
- * OAuth error event
778
- */
779
- interface OAuthErrorEvent {
780
- type: 'oauth:error';
781
- data: NAuthClientError;
782
- timestamp: number;
783
- }
784
- /**
785
- * Event listener callback function
786
- */
787
- type AuthEventListener = (event: AuthEvent) => void;
788
-
789
- /**
790
- * Social provider identifiers.
791
- */
792
- type SocialProvider = 'google' | 'apple' | 'facebook';
793
- /**
794
- * Options for starting a redirect-first social login flow.
795
- *
796
- * This is a web-first API:
797
- * - Browser navigates to backend `/auth/social/:provider/redirect`
798
- * - Backend completes OAuth, sets cookies (or returns exchange token), and redirects back
799
- */
800
- interface SocialLoginOptions {
801
- /**
802
- * Frontend route (recommended) or URL to redirect to after the backend callback completes.
803
- * Default: config.redirects.success || '/'
804
- */
805
- returnTo?: string;
806
- /**
807
- * Optional application state to round-trip back to the frontend.
808
- * Must be treated as non-secret.
809
- */
810
- appState?: string;
811
- /**
812
- * Optional flow action.
813
- * Default: 'login'
814
- */
815
- action?: 'login' | 'link';
816
- }
817
- /**
818
- * Linked social accounts response.
819
- */
820
- interface LinkedAccountsResponse {
821
- providers: SocialProvider[];
822
- }
823
- /**
824
- * Native social verification request (mobile).
825
- */
826
- interface SocialVerifyRequest {
827
- provider: SocialProvider;
828
- idToken?: string;
829
- accessToken?: string;
830
- authorizationCode?: string;
831
- }
832
-
833
- /**
834
- * Audit event types.
835
- */
836
- declare enum AuthAuditEventType {
837
- LOGIN_SUCCESS = "LOGIN_SUCCESS",
838
- LOGIN_FAILED = "LOGIN_FAILED",
839
- LOGOUT = "LOGOUT",
840
- TOKEN_REFRESH = "TOKEN_REFRESH",
841
- TOKEN_REVOKED = "TOKEN_REVOKED",
842
- SIGNUP_SUCCESS = "SIGNUP_SUCCESS",
843
- SIGNUP_FAILED = "SIGNUP_FAILED",
844
- EMAIL_VERIFIED = "EMAIL_VERIFIED",
845
- PHONE_VERIFIED = "PHONE_VERIFIED",
846
- VERIFICATION_FAILED = "VERIFICATION_FAILED",
847
- MFA_ENABLED = "MFA_ENABLED",
848
- MFA_DISABLED = "MFA_DISABLED",
849
- MFA_VERIFIED = "MFA_VERIFIED",
850
- MFA_FAILED = "MFA_FAILED",
851
- MFA_BACKUP_CODE_USED = "MFA_BACKUP_CODE_USED",
852
- PASSWORD_CHANGED = "PASSWORD_CHANGED",
853
- PASSWORD_RESET_REQUESTED = "PASSWORD_RESET_REQUESTED",
854
- PASSWORD_RESET_COMPLETED = "PASSWORD_RESET_COMPLETED",
855
- ACCOUNT_LOCKED = "ACCOUNT_LOCKED",
856
- ACCOUNT_UNLOCKED = "ACCOUNT_UNLOCKED",
857
- SUSPICIOUS_ACTIVITY = "SUSPICIOUS_ACTIVITY",
858
- ADAPTIVE_MFA_TRIGGERED = "ADAPTIVE_MFA_TRIGGERED",
859
- SOCIAL_LINK_SUCCESS = "SOCIAL_LINK_SUCCESS",
860
- SOCIAL_LINK_FAILED = "SOCIAL_LINK_FAILED",
861
- SOCIAL_UNLINK = "SOCIAL_UNLINK"
862
- }
863
- /**
864
- * Audit event status.
865
- */
866
- type AuthAuditEventStatus = 'SUCCESS' | 'FAILURE' | 'INFO' | 'SUSPICIOUS';
867
- /**
868
- * Individual audit event record.
869
- */
870
- interface AuthAuditEvent {
871
- id: number;
872
- userId: number;
873
- eventType: AuthAuditEventType;
874
- eventStatus: AuthAuditEventStatus;
875
- riskFactor?: number | null;
876
- riskFactors?: string[] | null;
877
- adaptiveMfaTriggered?: boolean | null;
878
- ipAddress?: string | null;
879
- ipCountry?: string | null;
880
- ipCity?: string | null;
881
- ipLatitude?: number | null;
882
- ipLongitude?: number | null;
883
- userAgent?: string | null;
884
- platform?: string | null;
885
- browser?: string | null;
886
- deviceId?: string | null;
887
- deviceName?: string | null;
888
- deviceType?: string | null;
889
- sessionId?: number | null;
890
- challengeSessionId?: number | null;
891
- authMethod?: string | null;
892
- performedBy?: string | null;
893
- reason?: string | null;
894
- description?: string | null;
895
- metadata?: Record<string, unknown> | null;
896
- createdAt: string | Date;
897
- }
898
- /**
899
- * Paginated audit history response.
900
- */
901
- interface AuditHistoryResponse {
902
- data: AuthAuditEvent[];
903
- total: number;
904
- page: number;
905
- limit: number;
906
- totalPages: number;
907
- }
908
-
909
- /**
910
- * Primary client for interacting with nauth-toolkit backend.
911
- */
912
- declare class NAuthClient {
913
- private readonly config;
914
- private readonly tokenManager;
915
- private readonly eventEmitter;
916
- private currentUser;
917
- /**
918
- * Create a new client instance.
919
- *
920
- * @param userConfig - Client configuration
921
- */
922
- constructor(userConfig: NAuthClientConfig);
923
- /**
924
- * Clean up resources.
925
- */
926
- dispose(): void;
927
- /**
928
- * Login with identifier and password.
929
- */
930
- login(identifier: string, password: string): Promise<AuthResponse>;
931
- /**
932
- * Signup with credentials.
933
- */
934
- signup(payload: SignupRequest): Promise<AuthResponse>;
935
- /**
936
- * Refresh tokens manually.
937
- */
938
- refreshTokens(): Promise<TokenResponse>;
939
- /**
940
- * Logout current session.
941
- *
942
- * Uses GET request to avoid CSRF token issues.
943
- *
944
- * @param forgetDevice - If true, also untrust the device (require MFA on next login)
945
- */
946
- logout(forgetDevice?: boolean): Promise<void>;
947
- /**
948
- * Logout all sessions.
949
- *
950
- * Revokes all active sessions for the current user across all devices.
951
- * Optionally revokes all trusted devices if forgetDevices is true.
952
- *
953
- * @param forgetDevices - If true, also revokes all trusted devices (default: false)
954
- * @returns Number of sessions revoked
955
- */
956
- logoutAll(forgetDevices?: boolean): Promise<{
957
- revokedCount: number;
958
- }>;
959
- /**
960
- * Respond to a challenge.
961
- *
962
- * Validates challenge response data before sending to backend.
963
- * Provides helpful error messages for common validation issues.
964
- *
965
- * @param response - Challenge response data
966
- * @returns Auth response from backend
967
- * @throws {NAuthClientError} If validation fails
968
- */
969
- respondToChallenge(response: ChallengeResponse): Promise<AuthResponse>;
970
- /**
971
- * Resend a challenge code.
972
- */
973
- resendCode(session: string): Promise<{
974
- destination: string;
975
- }>;
976
- /**
977
- * Get setup data for MFA.
978
- *
979
- * Returns method-specific setup information:
980
- * - TOTP: { secret, qrCode, manualEntryKey }
981
- * - SMS: { maskedPhone }
982
- * - Email: { maskedEmail }
983
- * - Passkey: WebAuthn registration options
984
- *
985
- * @param session - Challenge session token
986
- * @param method - MFA method to set up
987
- * @returns Setup data wrapped in GetSetupDataResponse
988
- */
989
- getSetupData(session: string, method: GetSetupDataRequest['method']): Promise<GetSetupDataResponse>;
990
- /**
991
- * Get challenge data (e.g., WebAuthn options).
992
- *
993
- * Returns challenge-specific data for verification flows.
994
- *
995
- * @param session - Challenge session token
996
- * @param method - Challenge method to get data for
997
- * @returns Challenge data wrapped in GetChallengeDataResponse
998
- */
999
- getChallengeData(session: string, method: GetChallengeDataRequest['method']): Promise<GetChallengeDataResponse>;
1000
- /**
1001
- * Get current user profile.
1002
- */
1003
- getProfile(): Promise<AuthUser>;
1004
- /**
1005
- * Update user profile.
1006
- */
1007
- updateProfile(updates: UpdateProfileRequest): Promise<AuthUser>;
1008
- /**
1009
- * Change user password.
1010
- */
1011
- changePassword(oldPassword: string, newPassword: string): Promise<void>;
1012
- /**
1013
- * Request a password reset code (forgot password).
1014
- */
1015
- forgotPassword(identifier: string): Promise<ForgotPasswordResponse>;
1016
- /**
1017
- * Confirm a password reset code and set a new password.
1018
- */
1019
- confirmForgotPassword(identifier: string, code: string, newPassword: string): Promise<ConfirmForgotPasswordResponse>;
1020
- /**
1021
- * Request password change (must change on next login).
1022
- */
1023
- requestPasswordChange(): Promise<void>;
1024
- /**
1025
- * Get MFA status.
1026
- */
1027
- getMfaStatus(): Promise<MFAStatus>;
1028
- /**
1029
- * Get MFA devices.
1030
- */
1031
- getMfaDevices(): Promise<unknown[]>;
1032
- /**
1033
- * Setup MFA device (authenticated user).
1034
- */
1035
- setupMfaDevice(method: string): Promise<unknown>;
1036
- /**
1037
- * Verify MFA setup (authenticated user).
1038
- */
1039
- verifyMfaSetup(method: string, setupData: Record<string, unknown>, deviceName?: string): Promise<{
1040
- deviceId: number;
1041
- }>;
1042
- /**
1043
- * Remove MFA method.
1044
- */
1045
- removeMfaDevice(method: string): Promise<{
1046
- message: string;
1047
- }>;
1048
- /**
1049
- * Set preferred MFA method.
1050
- *
1051
- * @param method - Device method to set as preferred ('totp', 'sms', 'email', or 'passkey'). Cannot be 'backup'.
1052
- * @returns Success message
1053
- */
1054
- setPreferredMfaMethod(method: 'totp' | 'sms' | 'email' | 'passkey'): Promise<{
1055
- message: string;
1056
- }>;
1057
- /**
1058
- * Generate backup codes.
1059
- */
1060
- generateBackupCodes(): Promise<string[]>;
1061
- /**
1062
- * Set MFA exemption (admin/test scenarios).
1063
- */
1064
- setMfaExemption(exempt: boolean, reason?: string): Promise<void>;
1065
- /**
1066
- * Subscribe to authentication events.
1067
- *
1068
- * Emits events throughout the auth lifecycle for custom logic, analytics, or UI updates.
1069
- *
1070
- * @param event - Event type to listen for, or '*' for all events
1071
- * @param listener - Callback function to handle the event
1072
- * @returns Unsubscribe function
1073
- *
1074
- * @example
1075
- * ```typescript
1076
- * // Listen to successful authentication
1077
- * const unsubscribe = client.on('auth:success', (event) => {
1078
- * console.log('User logged in:', event.data.user);
1079
- * analytics.track('login_success');
1080
- * });
1081
- *
1082
- * // Listen to all events
1083
- * client.on('*', (event) => {
1084
- * console.log('Auth event:', event.type, event.data);
1085
- * });
1086
- *
1087
- * // Unsubscribe when done
1088
- * unsubscribe();
1089
- * ```
1090
- */
1091
- on(event: AuthEventType | '*', listener: AuthEventListener): () => void;
1092
- /**
1093
- * Unsubscribe from authentication events.
1094
- *
1095
- * @param event - Event type
1096
- * @param listener - Callback function to remove
1097
- */
1098
- off(event: AuthEventType | '*', listener: AuthEventListener): void;
1099
- /**
1100
- * Start redirect-first social OAuth flow (web).
1101
- *
1102
- * This performs a browser navigation to:
1103
- * `GET {baseUrl}/social/:provider/redirect?returnTo=...&appState=...`
1104
- *
1105
- * The backend:
1106
- * - generates and stores CSRF state (cluster-safe)
1107
- * - redirects the user to the provider
1108
- * - completes OAuth on callback and sets cookies (or issues an exchange token)
1109
- * - redirects back to `returnTo` with `appState` (and `exchangeToken` for json/hybrid)
1110
- *
1111
- * @param provider - OAuth provider ('google', 'apple', 'facebook')
1112
- * @param options - Optional redirect options
1113
- *
1114
- * @example
1115
- * ```typescript
1116
- * await client.loginWithSocial('google', { returnTo: '/auth/callback', appState: '12345' });
1117
- * ```
1118
- */
1119
- loginWithSocial(provider: SocialProvider, options?: SocialLoginOptions): Promise<void>;
1120
- /**
1121
- * Exchange an `exchangeToken` (from redirect callback URL) into an AuthResponse.
1122
- *
1123
- * Used for `tokenDelivery: 'json'` or hybrid flows where the backend redirects back
1124
- * with `exchangeToken` instead of setting cookies.
1125
- *
1126
- * @param exchangeToken - One-time exchange token from the callback URL
1127
- * @returns AuthResponse
1128
- */
1129
- exchangeSocialRedirect(exchangeToken: string): Promise<AuthResponse>;
1130
- /**
1131
- * Verify native social token (mobile).
1132
- */
1133
- verifyNativeSocial(request: SocialVerifyRequest): Promise<AuthResponse>;
1134
- /**
1135
- * Get linked accounts.
1136
- */
1137
- getLinkedAccounts(): Promise<LinkedAccountsResponse>;
1138
- /**
1139
- * Link social account.
1140
- */
1141
- linkSocialAccount(provider: string, code: string, state: string): Promise<{
1142
- message: string;
1143
- }>;
1144
- /**
1145
- * Unlink social account.
1146
- */
1147
- unlinkSocialAccount(provider: string): Promise<{
1148
- message: string;
1149
- }>;
1150
- /**
1151
- * Trust current device.
1152
- */
1153
- trustDevice(): Promise<{
1154
- deviceToken: string;
1155
- }>;
1156
- /**
1157
- * Check if the current device is trusted.
1158
- *
1159
- * Returns whether the current device is trusted based on the device token
1160
- * (from cookie in cookies mode, or header in JSON mode).
1161
- *
1162
- * This performs a server-side validation of the device token and checks:
1163
- * - Device token exists and is valid
1164
- * - Device token matches a trusted device record in the database
1165
- * - Trust has not expired
1166
- *
1167
- * @returns Object with trusted status
1168
- *
1169
- * @example
1170
- * ```typescript
1171
- * const result = await client.isTrustedDevice();
1172
- * if (result.trusted) {
1173
- * console.log('This device is trusted');
1174
- * }
1175
- * ```
1176
- */
1177
- isTrustedDevice(): Promise<{
1178
- trusted: boolean;
1179
- }>;
1180
- /**
1181
- * Get paginated audit history for the current user.
1182
- *
1183
- * Returns authentication and security events with full audit details including:
1184
- * - Event type (login, logout, MFA, etc.)
1185
- * - Event status (success, failure, suspicious)
1186
- * - Device information, location, risk factors
1187
- *
1188
- * @param params - Query parameters for filtering and pagination
1189
- * @returns Paginated audit history response
1190
- *
1191
- * @example
1192
- * ```typescript
1193
- * const history = await client.getAuditHistory({
1194
- * page: 1,
1195
- * limit: 20,
1196
- * eventType: 'LOGIN_SUCCESS'
1197
- * });
1198
- * ```
1199
- */
1200
- getAuditHistory(params?: Record<string, string | number | boolean>): Promise<AuditHistoryResponse>;
1201
- /**
1202
- * Initialize client by hydrating state from storage.
1203
- * Call this on app startup to restore auth state.
1204
- */
1205
- initialize(): Promise<void>;
1206
- /**
1207
- * Determine if user is authenticated (async - checks tokens).
1208
- */
1209
- isAuthenticated(): Promise<boolean>;
1210
- /**
1211
- * Determine if user is authenticated (sync - checks cached user).
1212
- * Use this for guards and sync checks. Use `isAuthenticated()` for definitive check.
1213
- */
1214
- isAuthenticatedSync(): boolean;
1215
- /**
1216
- * Get current access token (may be null).
1217
- */
1218
- getAccessToken(): Promise<string | null>;
1219
- /**
1220
- * Get current user (cached, sync).
1221
- */
1222
- getCurrentUser(): AuthUser | null;
1223
- /**
1224
- * Get stored challenge session (for resuming challenge flows).
1225
- */
1226
- getStoredChallenge(): Promise<AuthResponse | null>;
1227
- /**
1228
- * Clear stored challenge session.
1229
- */
1230
- clearStoredChallenge(): Promise<void>;
1231
- /**
1232
- * Internal: handle auth response (tokens or challenge).
1233
- *
1234
- * In cookies mode: Tokens are set as httpOnly cookies by backend, not stored in client storage.
1235
- * In JSON mode: Tokens are stored in tokenManager for Authorization header.
1236
- */
1237
- private handleAuthResponse;
1238
- /**
1239
- * Persist challenge state.
1240
- */
1241
- private persistChallenge;
1242
- /**
1243
- * Clear challenge state.
1244
- */
1245
- private clearChallenge;
1246
- /**
1247
- * Persist user.
1248
- */
1249
- private setUser;
1250
- /**
1251
- * Clear all auth state.
1252
- *
1253
- * @param forgetDevice - If true, also clear device token (for JSON mode)
1254
- */
1255
- private clearAuthState;
1256
- /**
1257
- * Persist device token (json mode mobile).
1258
- */
1259
- private setDeviceToken;
1260
- /**
1261
- * Determine token delivery mode for this environment.
1262
- */
1263
- private getTokenDeliveryMode;
1264
- /**
1265
- * Build request URL by combining baseUrl with path.
1266
- * @private
1267
- */
1268
- private buildUrl;
1269
- /**
1270
- * Build request headers for authentication.
1271
- * @private
1272
- */
1273
- private buildHeaders;
1274
- /**
1275
- * Get CSRF token from cookie (browser only).
1276
- * @private
1277
- */
1278
- private getCsrfToken;
1279
- /**
1280
- * Execute GET request.
1281
- * Note: 401 refresh is handled by framework interceptors (Angular) or manually.
1282
- */
1283
- private get;
1284
- /**
1285
- * Execute POST request.
1286
- * Note: 401 refresh is handled by framework interceptors (Angular) or manually.
1287
- */
1288
- private post;
1289
- /**
1290
- * Execute PUT request.
1291
- * Note: 401 refresh is handled by framework interceptors (Angular) or manually.
1292
- */
1293
- private put;
1294
- /**
1295
- * Execute DELETE request.
1296
- * Note: 401 refresh is handled by framework interceptors (Angular) or manually.
1297
- */
1298
- private delete;
1299
- /**
1300
- * Handle cross-tab storage updates.
1301
- */
1302
- private readonly handleStorageEvent;
1303
- }
1304
-
1305
- /**
1306
- * Angular wrapper around NAuthClient that provides promise-based auth methods and reactive state.
1307
- *
1308
- * This service provides:
1309
- * - Reactive state (currentUser$, isAuthenticated$, challenge$)
1310
- * - All core auth methods as Promises (login, signup, logout, refresh)
1311
- * - Profile management (getProfile, updateProfile, changePassword)
1312
- * - Challenge flow methods (respondToChallenge, resendCode)
1313
- * - MFA management (getMfaStatus, setupMfaDevice, etc.)
1314
- * - Social authentication and account linking
1315
- * - Device trust management
1316
- * - Audit history
1317
- *
1318
- * @example
1319
- * ```typescript
1320
- * constructor(private auth: AuthService) {}
1321
- *
1322
- * // Reactive state
1323
- * this.auth.currentUser$.subscribe(user => ...);
1324
- * this.auth.isAuthenticated$.subscribe(isAuth => ...);
1325
- *
1326
- * // Auth operations with async/await
1327
- * const response = await this.auth.login(email, password);
1328
- *
1329
- * // Profile management
1330
- * await this.auth.changePassword(oldPassword, newPassword);
1331
- * const user = await this.auth.updateProfile({ firstName: 'John' });
1332
- *
1333
- * // MFA operations
1334
- * const status = await this.auth.getMfaStatus();
1335
- * ```
1336
- */
1337
- declare class AuthService {
1338
- private injector?;
1339
- private readonly client;
1340
- private readonly config;
1341
- private readonly currentUserSubject;
1342
- private readonly isAuthenticatedSubject;
1343
- private readonly challengeSubject;
1344
- private readonly authEventsSubject;
1345
- private initialized;
1346
- /**
1347
- * @param config - Injected client configuration
1348
- *
1349
- * Note: AngularHttpAdapter is automatically injected via Angular DI.
1350
- * This ensures all requests go through Angular's HttpClient and interceptors.
1351
- */
1352
- constructor(config?: NAuthClientConfig, injector?: Injector | undefined);
1353
- /**
1354
- * Current user observable.
1355
- */
1356
- get currentUser$(): Observable<AuthUser | null>;
1357
- /**
1358
- * Authenticated state observable.
1359
- */
1360
- get isAuthenticated$(): Observable<boolean>;
1361
- /**
1362
- * Current challenge observable (for reactive challenge navigation).
1363
- */
1364
- get challenge$(): Observable<AuthResponse | null>;
1365
- /**
1366
- * Authentication events stream.
1367
- * Emits all auth lifecycle events for custom logic, analytics, or UI updates.
1368
- */
1369
- get authEvents$(): Observable<AuthEvent>;
1370
- /**
1371
- * Successful authentication events stream.
1372
- * Emits when user successfully authenticates (login, signup, social auth).
1373
- */
1374
- get authSuccess$(): Observable<AuthEvent>;
1375
- /**
1376
- * Authentication error events stream.
1377
- * Emits when authentication fails (login error, OAuth error, etc.).
1378
- */
1379
- get authError$(): Observable<AuthEvent>;
1380
- /**
1381
- * Check if authenticated (sync, uses cached state).
1382
- */
1383
- isAuthenticated(): boolean;
1384
- /**
1385
- * Get current user (sync, uses cached state).
1386
- */
1387
- getCurrentUser(): AuthUser | null;
1388
- /**
1389
- * Get current challenge (sync).
1390
- */
1391
- getCurrentChallenge(): AuthResponse | null;
1392
- /**
1393
- * Login with identifier and password.
1394
- *
1395
- * @param identifier - User email or username
1396
- * @param password - User password
1397
- * @returns Promise with auth response or challenge
1398
- *
1399
- * @example
1400
- * ```typescript
1401
- * const response = await this.auth.login('user@example.com', 'password');
1402
- * if (response.challengeName) {
1403
- * // Handle challenge
1404
- * } else {
1405
- * // Login successful
1406
- * }
1407
- * ```
1408
- */
1409
- login(identifier: string, password: string): Promise<AuthResponse>;
1410
- /**
1411
- * Signup with credentials.
1412
- *
1413
- * @param payload - Signup request payload
1414
- * @returns Promise with auth response or challenge
1415
- *
1416
- * @example
1417
- * ```typescript
1418
- * const response = await this.auth.signup({
1419
- * email: 'new@example.com',
1420
- * password: 'SecurePass123!',
1421
- * firstName: 'John',
1422
- * });
1423
- * ```
1424
- */
1425
- signup(payload: Parameters<NAuthClient['signup']>[0]): Promise<AuthResponse>;
1426
- /**
1427
- * Logout current session.
1428
- *
1429
- * @param forgetDevice - If true, removes device trust
1430
- *
1431
- * @example
1432
- * ```typescript
1433
- * await this.auth.logout();
1434
- * ```
1435
- */
1436
- logout(forgetDevice?: boolean): Promise<void>;
1437
- /**
1438
- * Logout all sessions.
1439
- *
1440
- * Revokes all active sessions for the current user across all devices.
1441
- * Optionally revokes all trusted devices if forgetDevices is true.
1442
- *
1443
- * @param forgetDevices - If true, also revokes all trusted devices (default: false)
1444
- * @returns Promise with number of sessions revoked
1445
- *
1446
- * @example
1447
- * ```typescript
1448
- * const result = await this.auth.logoutAll();
1449
- * console.log(`Revoked ${result.revokedCount} sessions`);
1450
- * ```
1451
- */
1452
- logoutAll(forgetDevices?: boolean): Promise<{
1453
- revokedCount: number;
1454
- }>;
1455
- /**
1456
- * Refresh tokens.
1457
- *
1458
- * @returns Promise with new tokens
1459
- *
1460
- * @example
1461
- * ```typescript
1462
- * const tokens = await this.auth.refresh();
1463
- * ```
1464
- */
1465
- refresh(): Promise<TokenResponse>;
1466
- /**
1467
- * Request a password reset code (forgot password).
1468
- *
1469
- * @param identifier - User email, username, or phone
1470
- * @returns Promise with password reset response
1471
- *
1472
- * @example
1473
- * ```typescript
1474
- * await this.auth.forgotPassword('user@example.com');
1475
- * ```
1476
- */
1477
- forgotPassword(identifier: string): Promise<ForgotPasswordResponse>;
1478
- /**
1479
- * Confirm a password reset code and set a new password.
1480
- *
1481
- * @param identifier - User email, username, or phone
1482
- * @param code - One-time reset code
1483
- * @param newPassword - New password
1484
- * @returns Promise with confirmation response
1485
- *
1486
- * @example
1487
- * ```typescript
1488
- * await this.auth.confirmForgotPassword('user@example.com', '123456', 'NewPass123!');
1489
- * ```
1490
- */
1491
- confirmForgotPassword(identifier: string, code: string, newPassword: string): Promise<ConfirmForgotPasswordResponse>;
1492
- /**
1493
- * Change user password (requires current password).
1494
- *
1495
- * @param oldPassword - Current password
1496
- * @param newPassword - New password (must meet requirements)
1497
- * @returns Promise that resolves when password is changed
1498
- *
1499
- * @example
1500
- * ```typescript
1501
- * await this.auth.changePassword('oldPassword123', 'newSecurePassword456!');
1502
- * ```
1503
- */
1504
- changePassword(oldPassword: string, newPassword: string): Promise<void>;
1505
- /**
1506
- * Request password change (must change on next login).
1507
- *
1508
- * @returns Promise that resolves when request is sent
1509
- *
1510
- * @example
1511
- * ```typescript
1512
- * await this.auth.requestPasswordChange();
1513
- * ```
1514
- */
1515
- requestPasswordChange(): Promise<void>;
1516
- /**
1517
- * Get current user profile.
1518
- *
1519
- * @returns Promise of current user profile
1520
- *
1521
- * @example
1522
- * ```typescript
1523
- * const user = await this.auth.getProfile();
1524
- * console.log('User profile:', user);
1525
- * ```
1526
- */
1527
- getProfile(): Promise<AuthUser>;
1528
- /**
1529
- * Update user profile.
1530
- *
1531
- * @param updates - Profile fields to update
1532
- * @returns Promise of updated user profile
1533
- *
1534
- * @example
1535
- * ```typescript
1536
- * const user = await this.auth.updateProfile({ firstName: 'John', lastName: 'Doe' });
1537
- * console.log('Profile updated:', user);
1538
- * ```
1539
- */
1540
- updateProfile(updates: UpdateProfileRequest): Promise<AuthUser>;
1541
- /**
1542
- * Respond to a challenge (VERIFY_EMAIL, VERIFY_PHONE, MFA_REQUIRED, etc.).
1543
- *
1544
- * @param response - Challenge response data
1545
- * @returns Promise with auth response or next challenge
1546
- *
1547
- * @example
1548
- * ```typescript
1549
- * const result = await this.auth.respondToChallenge({
1550
- * session: challengeSession,
1551
- * type: 'VERIFY_EMAIL',
1552
- * code: '123456',
1553
- * });
1554
- * ```
1555
- */
1556
- respondToChallenge(response: ChallengeResponse): Promise<AuthResponse>;
1557
- /**
1558
- * Resend challenge code.
1559
- *
1560
- * @param session - Challenge session token
1561
- * @returns Promise with destination information
1562
- *
1563
- * @example
1564
- * ```typescript
1565
- * const result = await this.auth.resendCode(session);
1566
- * console.log('Code sent to:', result.destination);
1567
- * ```
1568
- */
1569
- resendCode(session: string): Promise<{
1570
- destination: string;
1571
- }>;
1572
- /**
1573
- * Get MFA setup data (for MFA_SETUP_REQUIRED challenge).
1574
- *
1575
- * Returns method-specific setup information:
1576
- * - TOTP: { secret, qrCode, manualEntryKey }
1577
- * - SMS: { maskedPhone }
1578
- * - Email: { maskedEmail }
1579
- * - Passkey: WebAuthn registration options
1580
- *
1581
- * @param session - Challenge session token
1582
- * @param method - MFA method to set up
1583
- * @returns Promise of setup data response
1584
- *
1585
- * @example
1586
- * ```typescript
1587
- * const setupData = await this.auth.getSetupData(session, 'totp');
1588
- * console.log('QR Code:', setupData.setupData.qrCode);
1589
- * ```
1590
- */
1591
- getSetupData(session: string, method: string): Promise<GetSetupDataResponse>;
1592
- /**
1593
- * Get MFA challenge data (for MFA_REQUIRED challenge - e.g., passkey options).
1594
- *
1595
- * @param session - Challenge session token
1596
- * @param method - Challenge method
1597
- * @returns Promise of challenge data response
1598
- *
1599
- * @example
1600
- * ```typescript
1601
- * const challengeData = await this.auth.getChallengeData(session, 'passkey');
1602
- * ```
1603
- */
1604
- getChallengeData(session: string, method: string): Promise<GetChallengeDataResponse>;
1605
- /**
1606
- * Clear stored challenge (when navigating away from challenge flow).
1607
- *
1608
- * @returns Promise that resolves when challenge is cleared
1609
- *
1610
- * @example
1611
- * ```typescript
1612
- * await this.auth.clearChallenge();
1613
- * ```
1614
- */
1615
- clearChallenge(): Promise<void>;
1616
- /**
1617
- * Initiate social OAuth login flow.
1618
- * Redirects the browser to backend `/auth/social/:provider/redirect`.
1619
- *
1620
- * @param provider - Social provider ('google', 'apple', 'facebook')
1621
- * @param options - Optional redirect options
1622
- * @returns Promise that resolves when redirect starts
1623
- *
1624
- * @example
1625
- * ```typescript
1626
- * await this.auth.loginWithSocial('google', { returnTo: '/auth/callback' });
1627
- * ```
1628
- */
1629
- loginWithSocial(provider: SocialProvider, options?: SocialLoginOptions): Promise<void>;
1630
- /**
1631
- * Exchange an exchangeToken (from redirect callback URL) into an AuthResponse.
1632
- *
1633
- * Used for `tokenDelivery: 'json'` or hybrid flows where the backend redirects back
1634
- * with `exchangeToken` instead of setting cookies.
1635
- *
1636
- * @param exchangeToken - One-time exchange token from the callback URL
1637
- * @returns Promise of AuthResponse
1638
- *
1639
- * @example
1640
- * ```typescript
1641
- * const response = await this.auth.exchangeSocialRedirect(exchangeToken);
1642
- * ```
1643
- */
1644
- exchangeSocialRedirect(exchangeToken: string): Promise<AuthResponse>;
1645
- /**
1646
- * Verify native social token (mobile).
1647
- *
1648
- * @param request - Social verification request with provider and token
1649
- * @returns Promise of AuthResponse
1650
- *
1651
- * @example
1652
- * ```typescript
1653
- * const result = await this.auth.verifyNativeSocial({
1654
- * provider: 'google',
1655
- * idToken: nativeIdToken,
1656
- * });
1657
- * ```
1658
- */
1659
- verifyNativeSocial(request: SocialVerifyRequest): Promise<AuthResponse>;
1660
- /**
1661
- * Get linked social accounts.
1662
- *
1663
- * @returns Promise of linked accounts response
1664
- *
1665
- * @example
1666
- * ```typescript
1667
- * const accounts = await this.auth.getLinkedAccounts();
1668
- * console.log('Linked providers:', accounts.providers);
1669
- * ```
1670
- */
1671
- getLinkedAccounts(): Promise<LinkedAccountsResponse>;
1672
- /**
1673
- * Link social account.
1674
- *
1675
- * @param provider - Social provider to link
1676
- * @param code - OAuth authorization code
1677
- * @param state - OAuth state parameter
1678
- * @returns Promise with success message
1679
- *
1680
- * @example
1681
- * ```typescript
1682
- * await this.auth.linkSocialAccount('google', code, state);
1683
- * ```
1684
- */
1685
- linkSocialAccount(provider: string, code: string, state: string): Promise<{
1686
- message: string;
1687
- }>;
1688
- /**
1689
- * Unlink social account.
1690
- *
1691
- * @param provider - Social provider to unlink
1692
- * @returns Promise with success message
1693
- *
1694
- * @example
1695
- * ```typescript
1696
- * await this.auth.unlinkSocialAccount('google');
1697
- * ```
1698
- */
1699
- unlinkSocialAccount(provider: string): Promise<{
1700
- message: string;
1701
- }>;
1702
- /**
1703
- * Get MFA status for the current user.
1704
- *
1705
- * @returns Promise of MFA status
1706
- *
1707
- * @example
1708
- * ```typescript
1709
- * const status = await this.auth.getMfaStatus();
1710
- * console.log('MFA enabled:', status.enabled);
1711
- * ```
1712
- */
1713
- getMfaStatus(): Promise<MFAStatus>;
1714
- /**
1715
- * Get MFA devices for the current user.
1716
- *
1717
- * @returns Promise of MFA devices array
1718
- *
1719
- * @example
1720
- * ```typescript
1721
- * const devices = await this.auth.getMfaDevices();
1722
- * ```
1723
- */
1724
- getMfaDevices(): Promise<MFADevice[]>;
1725
- /**
1726
- * Setup MFA device (authenticated user).
1727
- *
1728
- * @param method - MFA method to set up
1729
- * @returns Promise of setup data
1730
- *
1731
- * @example
1732
- * ```typescript
1733
- * const setupData = await this.auth.setupMfaDevice('totp');
1734
- * ```
1735
- */
1736
- setupMfaDevice(method: string): Promise<unknown>;
1737
- /**
1738
- * Verify MFA setup (authenticated user).
1739
- *
1740
- * @param method - MFA method
1741
- * @param setupData - Setup data from setupMfaDevice
1742
- * @param deviceName - Optional device name
1743
- * @returns Promise with device ID
1744
- *
1745
- * @example
1746
- * ```typescript
1747
- * const result = await this.auth.verifyMfaSetup('totp', { code: '123456' }, 'My Phone');
1748
- * ```
1749
- */
1750
- verifyMfaSetup(method: string, setupData: Record<string, unknown>, deviceName?: string): Promise<{
1751
- deviceId: number;
1752
- }>;
1753
- /**
1754
- * Remove MFA device.
1755
- *
1756
- * @param method - MFA method to remove
1757
- * @returns Promise with success message
1758
- *
1759
- * @example
1760
- * ```typescript
1761
- * await this.auth.removeMfaDevice('sms');
1762
- * ```
1763
- */
1764
- removeMfaDevice(method: string): Promise<{
1765
- message: string;
1766
- }>;
1767
- /**
1768
- * Set preferred MFA method.
1769
- *
1770
- * @param method - Device method to set as preferred ('totp', 'sms', 'email', or 'passkey')
1771
- * @returns Promise with success message
1772
- *
1773
- * @example
1774
- * ```typescript
1775
- * await this.auth.setPreferredMfaMethod('totp');
1776
- * ```
1777
- */
1778
- setPreferredMfaMethod(method: 'totp' | 'sms' | 'email' | 'passkey'): Promise<{
1779
- message: string;
1780
- }>;
1781
- /**
1782
- * Generate backup codes.
1783
- *
1784
- * @returns Promise of backup codes array
1785
- *
1786
- * @example
1787
- * ```typescript
1788
- * const codes = await this.auth.generateBackupCodes();
1789
- * console.log('Backup codes:', codes);
1790
- * ```
1791
- */
1792
- generateBackupCodes(): Promise<string[]>;
1793
- /**
1794
- * Set MFA exemption (admin/test scenarios).
1795
- *
1796
- * @param exempt - Whether to exempt user from MFA
1797
- * @param reason - Optional reason for exemption
1798
- * @returns Promise that resolves when exemption is set
1799
- *
1800
- * @example
1801
- * ```typescript
1802
- * await this.auth.setMfaExemption(true, 'Test account');
1803
- * ```
1804
- */
1805
- setMfaExemption(exempt: boolean, reason?: string): Promise<void>;
1806
- /**
1807
- * Trust current device.
1808
- *
1809
- * @returns Promise with device token
1810
- *
1811
- * @example
1812
- * ```typescript
1813
- * const result = await this.auth.trustDevice();
1814
- * console.log('Device trusted:', result.deviceToken);
1815
- * ```
1816
- */
1817
- trustDevice(): Promise<{
1818
- deviceToken: string;
1819
- }>;
1820
- /**
1821
- * Check if the current device is trusted.
1822
- *
1823
- * @returns Promise with trusted status
1824
- *
1825
- * @example
1826
- * ```typescript
1827
- * const result = await this.auth.isTrustedDevice();
1828
- * if (result.trusted) {
1829
- * console.log('This device is trusted');
1830
- * }
1831
- * ```
1832
- */
1833
- isTrustedDevice(): Promise<{
1834
- trusted: boolean;
1835
- }>;
1836
- /**
1837
- * Get paginated audit history for the current user.
1838
- *
1839
- * @param params - Query parameters for filtering and pagination
1840
- * @returns Promise of audit history response
1841
- *
1842
- * @example
1843
- * ```typescript
1844
- * const history = await this.auth.getAuditHistory({
1845
- * page: 1,
1846
- * limit: 20,
1847
- * eventType: 'LOGIN_SUCCESS'
1848
- * });
1849
- * console.log('Audit history:', history);
1850
- * ```
1851
- */
1852
- getAuditHistory(params?: Record<string, string | number | boolean>): Promise<AuditHistoryResponse>;
1853
- /**
1854
- * Expose underlying NAuthClient for advanced scenarios.
1855
- *
1856
- * @deprecated All core functionality is now exposed directly on AuthService as Promises.
1857
- * Use the direct methods on AuthService instead (e.g., `auth.changePassword()` instead of `auth.getClient().changePassword()`).
1858
- * This method is kept for backward compatibility only and may be removed in a future version.
1859
- *
1860
- * @returns The underlying NAuthClient instance
1861
- *
1862
- * @example
1863
- * ```typescript
1864
- * // Deprecated - use direct methods instead
1865
- * const status = await this.auth.getClient().getMfaStatus();
1866
- *
1867
- * // Preferred - use direct methods
1868
- * const status = await this.auth.getMfaStatus();
1869
- * ```
1870
- */
1871
- getClient(): NAuthClient;
1872
- /**
1873
- * Initialize by hydrating state from storage.
1874
- * Called automatically on construction.
1875
- */
1876
- private initialize;
1877
- /**
1878
- * Update challenge state after auth response.
1879
- */
1880
- private updateChallengeState;
1881
- }
1882
-
1883
- /**
1884
- * Angular HTTP interceptor for nauth-toolkit.
1885
- *
1886
- * Handles:
1887
- * - Cookies mode: withCredentials + CSRF tokens + refresh via POST
1888
- * - JSON mode: refresh via SDK, retry with new token
1889
- */
1890
- declare const authInterceptor: HttpInterceptorFn;
1891
- /**
1892
- * Class-based interceptor for NgModule compatibility.
1893
- */
1894
- declare class AuthInterceptor {
1895
- intercept(req: HttpRequest$1<unknown>, next: HttpHandlerFn): rxjs.Observable<_angular_common_http.HttpEvent<unknown>>;
1896
- }
1897
-
1898
- /**
1899
- * Functional route guard for authentication (Angular 17+).
1900
- *
1901
- * Protects routes by checking if user is authenticated.
1902
- * Redirects to login page if not authenticated.
1903
- *
1904
- * @param redirectTo - Path to redirect to if not authenticated (default: '/login')
1905
- * @returns CanActivateFn guard function
1906
- *
1907
- * @example
1908
- * ```typescript
1909
- * // In route configuration
1910
- * const routes: Routes = [
1911
- * {
1912
- * path: 'home',
1913
- * component: HomeComponent,
1914
- * canActivate: [authGuard()]
1915
- * },
1916
- * {
1917
- * path: 'admin',
1918
- * component: AdminComponent,
1919
- * canActivate: [authGuard('/admin/login')]
1920
- * }
1921
- * ];
1922
- * ```
1923
- */
1924
- declare function authGuard(redirectTo?: string): CanActivateFn;
1925
- /**
1926
- * Class-based authentication guard for NgModule compatibility.
1927
- *
1928
- * @example
1929
- * ```typescript
1930
- * // In route configuration (NgModule)
1931
- * const routes: Routes = [
1932
- * {
1933
- * path: 'home',
1934
- * component: HomeComponent,
1935
- * canActivate: [AuthGuard]
1936
- * }
1937
- * ];
1938
- *
1939
- * // In module providers
1940
- * @NgModule({
1941
- * providers: [AuthGuard]
1942
- * })
1943
- * ```
1944
- */
1945
- declare class AuthGuard {
1946
- private auth;
1947
- private router;
1948
- /**
1949
- * @param auth - Authentication service
1950
- * @param router - Angular router
1951
- */
1952
- constructor(auth: AuthService, router: Router);
1953
- /**
1954
- * Check if route can be activated.
1955
- *
1956
- * @returns True if authenticated, otherwise redirects to login
1957
- */
1958
- canActivate(): boolean | UrlTree;
1959
- }
1960
-
1961
- /**
1962
- * Social redirect callback route guard.
1963
- *
1964
- * This guard supports the redirect-first social flow where the backend redirects
1965
- * back to the frontend with:
1966
- * - `appState` (always optional)
1967
- * - `exchangeToken` (present for json/hybrid flows, and for cookie flows that return a challenge)
1968
- * - `error` / `error_description` (provider errors)
1969
- *
1970
- * Behavior:
1971
- * - If `exchangeToken` exists: exchanges it via backend and redirects to success or challenge routes.
1972
- * - If no `exchangeToken`: treat as cookie-success path and redirect to success route.
1973
- * - If `error` exists: redirects to oauthError route.
1974
- *
1975
- * @example
1976
- * ```typescript
1977
- * import { socialRedirectCallbackGuard } from '@nauth-toolkit/client/angular';
1978
- *
1979
- * export const routes: Routes = [
1980
- * { path: 'auth/callback', canActivate: [socialRedirectCallbackGuard], component: CallbackComponent },
1981
- * ];
1982
- * ```
1983
- */
1984
- declare const socialRedirectCallbackGuard: CanActivateFn;
1985
-
1986
- /**
1987
- * NgModule wrapper to provide configuration and interceptor.
1988
- */
1989
- declare class NAuthModule {
1990
- /**
1991
- * Configure the module with client settings.
1992
- *
1993
- * @param config - Client configuration
1994
- */
1995
- static forRoot(config: NAuthClientConfig): ModuleWithProviders<NAuthModule>;
1996
- }
1997
-
1998
- /**
1999
- * HTTP adapter for Angular using HttpClient.
2000
- *
2001
- * This adapter:
2002
- * - Uses Angular's HttpClient for all requests
2003
- * - Works with Angular's HTTP interceptors (including authInterceptor)
2004
- * - Auto-provided via Angular DI (providedIn: 'root')
2005
- * - Converts HttpClient responses to HttpResponse format
2006
- * - Converts HttpErrorResponse to NAuthClientError
2007
- *
2008
- * Users don't need to configure this manually - it's automatically
2009
- * injected when using AuthService in Angular apps.
2010
- *
2011
- * @example
2012
- * ```typescript
2013
- * // Automatic usage (no manual setup needed)
2014
- * // AuthService automatically injects AngularHttpAdapter
2015
- * constructor(private auth: AuthService) {}
2016
- * ```
2017
- */
2018
- declare class AngularHttpAdapter implements HttpAdapter {
2019
- private readonly http;
2020
- /**
2021
- * Execute HTTP request using Angular's HttpClient.
2022
- *
2023
- * @param config - Request configuration
2024
- * @returns Response with parsed data
2025
- * @throws NAuthClientError if request fails
2026
- */
2027
- request<T>(config: HttpRequest): Promise<HttpResponse<T>>;
2028
- }
2029
-
2030
- export { AngularHttpAdapter, AuthChallenge, type AuthEvent, type AuthEventListener, type AuthEventType, AuthGuard, AuthInterceptor, type AuthResponse, AuthService, type AuthUser, type ChallengeResponse, type HttpAdapter, type MFADeviceMethod, type MFAMethod, type MFAStatus, NAUTH_CLIENT_CONFIG, type NAuthClientConfig, NAuthModule, type SocialProvider, type TokenDeliveryMode, type TokenResponse, authGuard, authInterceptor, socialRedirectCallbackGuard };